使用包管理工具Govendor安装gin的Web框架
1. go get govendor
go get github.com/kardianos/govendor
2. Create your project folder and cd inside
mkdir -p $GOPATH/src/song && cd "$_"
3. Vendor init your project and add gin
govendor init
govendor fetch github.com/gin-gonic/[email protected]
4. Copy a starting template inside your project
curl https://raw.githubusercontent.com/gin-gonic/examples/master/basic/main.go > main.go
5. Build your project
go build main.go
此时会报错:
vendor/github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/root/go/src/song/vendor/github.com/golang/protobuf/proto (vendor tree)
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/root/go/src/github.com/golang/protobuf/proto (from $GOPATH)
vendor/github.com/mattn/go-isatty/isatty_tcgets.go:7:8: cannot find package "golang.org/x/sys/unix" in any of:
/root/go/src/song/vendor/golang.org/x/sys/unix (vendor tree)
/usr/local/go/src/golang.org/x/sys/unix (from $GOROOT)
/root/go/src/golang.org/x/sys/unix (from $GOPATH)
vendor/github.com/gin-gonic/gin/binding/default_validator.go:11:2: cannot find package "gopkg.in/go-playground/validator.v8" in any of:
/root/go/src/song/vendor/gopkg.in/go-playground/validator.v8 (vendor tree)
/usr/local/go/src/gopkg.in/go-playground/validator.v8 (from $GOROOT)
/root/go/src/gopkg.in/go-playground/validator.v8 (from $GOPATH)
解决办法:
govendor fetch gopkg.in/go-playground/validator.v8
govendor fetch github.com/golang/protobuf/proto
govendor fetch golang.org/x/sys/unix //这条不管用
代替: cd /root/go/src/song/vendor/golang.org/x
git clone https://github.com/golang/sys.git
6. run
./main