2018 Golang Update(4)Dependency and Build

2018 Golang Update(4)Dependency and Build

Install dep on Mac
>brew install dep

Check version
>dep version
dep:
version     : v0.4.1
build date  : 2018-01-27
git hash    : 37d9ea0
go version  : go1.9.3
go compiler : gc
platform    : darwin/amd64

Go to the main.go directory
>cd /Users/carl/work/sillycat/monitor-water/restful_go_api/src/sillycat.com/restful_go_api
>dep init -v

It generate the Gopkg.lock and Gopkg.toml and a directory vendor/

Check the current status
>dep status
PROJECT                              CONSTRAINT     VERSION        REVISION  LATEST   PKGS USED
github.com/gin-contrib/sse           branch master  branch master  22d885f   22d885f  1 
github.com/gin-gonic/gin             ^1.2.0         v1.2           d459835   v1.2     3 
github.com/go-sql-driver/mysql       ^1.3.0         v1.3           a0583e0   v1.3     1 
github.com/go-xorm/builder           branch master  branch master  4882244   4882244  1 
github.com/go-xorm/core              ^0.5.7         v0.5.7         da1adaf   v0.5.7   1 
github.com/go-xorm/xorm              ^0.6.4         v0.6.4         1933dd6   v0.6.4   1 
github.com/golang/protobuf           v1.0.0         v1.0.0         9255415   v1.0.0   1 
github.com/mattn/go-isatty           v0.0.3         v0.0.3         0360b2a   v0.0.3   1 
github.com/ugorji/go                 v1.1           v1.1           9831f2c   v1.1     1 
golang.org/x/sys                     branch master  branch master  37707fd   37707fd  1 
gopkg.in/go-playground/validator.v8  v8.18.2        v8.18.2        5f1438d   v8.18.2  1 
gopkg.in/yaml.v2                     branch v2      branch v2      d670f94   d670f94  1 

If package is missing, it will tell us.

Download all the DEP
>dep ensure

Download the update the lock file and vendor directory
>dep ensure -update

Install Go on CentOS
>wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
Unzip and place in the working directory
>sudo ln -s ~/tool/go-1.10 /opt/go-1.10
>sudo ln -s /opt/go-1.10 /opt/go

GOROOT=/opt/go
GOPATH=/home/ec2-user/users/carl/monitor-water/restful_go_api

export GOROOT
export GOPATH

PATH=$PATH:/opt/go/bin

Who is doing this un professional things on our production server….
>type go
go is aliased to `git checkout'
>unalias go
>type go
go is /opt/go/bin/go

Check version
>go version
go version go1.10 linux/amd64

Install dep on the machine
>curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
It will install a dep in bin directory

>bin/dep version
dep:
version     : devel
build date  :
git hash    :
go version  : go1.10
go compiler : gc
platform    : linux/amd64

Run the download command
>dep ensure
>dep ensure -update

Then the build will work
>go install sillycat.com/restful_go_api

RaspberryPi Installation
>wget https://dl.google.com/go/go1.10.linux-armv6l.tar.gz
Unzip and place that in working directory

Prepare the directory
>sudo ln -s /home/carl/work /opt/work
>mkdir /opt/work/go/bin

Add these in the PATH
PATH="/opt/go/bin:$PATH"
export GOROOT="/opt/go"
export GOPATH="/opt/work/go"

Check go version
>go version
go version go1.10 linux/arm

Try to install dep
>curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
Architecture armv7l is not supported by this installation script

In my working directory
>pwd
/opt/work/go

Try to get the source
>go get -u github.com/golang/dep/cmd/dep

Install that to bin directory
>go install github.com/golang/dep/cmd/dep

It is there after installation
>ls -l bin
total 11068
-rwxr-xr-x 1 carl carl 11411230 Feb 22 09:50 dep

Add to Path
PATH="/opt/work/go/bin:$PATH"

Check the version
>dep version
dep:
version     : devel
build date  :
git hash    :
go version  : go1.10
go compiler : gc
platform    : linux/arm

Go to the directory of the project, main.go directory
>pwd
/home/carl/work/monitor-water/restful_go_api/src/sillycat.com/restful_go_api

Download all dependencies
>dep ensure

Build on raspberryPi
>go install sillycat.com/restful_go_api


References:
http://bazingafeng.com/2017/07/11/godep-for-managing-go-package-dependencies/
https://github.com/golang/dep

猜你喜欢

转载自sillycat.iteye.com/blog/2411230
今日推荐