Golang 1.8 installation and Govendor
We'd like to talk more about govendor, since we need a individual dependency for each project.
Install Golang Package
wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
tar -xvf go1.8.3.linux-amd64.tar.gz
mv go /usr/local
Setup Environment
export GOROOT="/usr/local/go"
export GOPATH="/go"
export GOBIN="/go/bin"
Store Environment
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
We also export binary directory, so we can direct launch it after go-install.
root@golang183:/go/src/github.com/jj# go env
GOARCH="amd64"
GOBIN="/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
Install VIM Development Environment
see my previous blog
http://gogosatellite.blogspot.tw/search?q=golang
Install Govendor
Let's started install govendor
go get -u github.com/kardianos/govendor
go to subdirectory, since we need a private package not global packages.
/go/src/github.com/jj
root@golang183:/go/src/github.com/jj# ls
a.go vendor
It will create vendor directory.
Now let's install a package
govendor fetch gopkg.in/cheggaaa/pb.v1
Now we install pb
package to vendor
directory.
root@golang183:/go/src/github.com/jj# ls vendor/
github.com gopkg.in vendor.json
Build and Install After Govendor
Here is the source code.
package main
import (
"gopkg.in/cheggaaa/pb.v1"
"time"
)
func main() {
count := 100000
bar := pb.StartNew(count)
for i := 0; i < count; i++ {
bar.Increment()
time.Sleep(time.Millisecond)
}
bar.FinishPrint("The End!")
}
Build and Install
root@golang183:/go/src/github.com/jj# go build
root@golang183:/go/src/github.com/jj# ls
a.go jj vendor
root@golang183:/go/src/github.com/jj# go install
root@golang183:/go/src/github.com/jj# which jj
/go/bin/jj
Reboot Setup
root@golang183:# cat /etc/profile.d/golang.sh
export GOROOT=/usr/local/go
export GOPATH=/go
export GOBIN=/go/bin
export GOARCH=amd64
export GOOS=linux
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Result
Now we have a individual package dependency for each project.
for example, we can have /go/src/github.com/bb
project and its own vendor for building binary.
No comments:
Post a Comment