在使用go的時(shí)候如果依賴導(dǎo)入github上的,比如下面樣式
import "github.com/go-sql-driver/mysql"
我們需要先執(zhí)行g(shù)et操作
go get github.com/go-sql-driver/mysql
它會(huì)下載到你的gopath目錄下
我看的項(xiàng)目是這個(gè)
https://blog.csdn.net/u010649766/article/details/79458004
GOROOT=/usr/local/go #gosetup
GOPATH=/mouse/study/goSpace/goTestSpace #gosetup
/usr/local/go/bin/go build -i -o /private/var/folders/6y/dnlwm8zn67d_10p7qjmml1r40000gn/T/___go_build_main_go /mouse/study/ownerWorkSpace/go/goTest/tlsdemo/demo/main.go #gosetup
../../../../goSpace/goTestSpace/src/github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/github.com/golang/protobuf/proto (vendor tree)
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/github.com/golang/protobuf/proto (from $GOPATH)
../../../../goSpace/goTestSpace/src/github.com/gin-gonic/gin/logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/github.com/mattn/go-isatty (vendor tree)
/usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/github.com/mattn/go-isatty (from $GOPATH)
../../../../goSpace/goTestSpace/src/github.com/gin-gonic/gin/binding/msgpack.go:12:2: cannot find package "github.com/ugorji/go/codec" in any of:
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/github.com/ugorji/go/codec (vendor tree)
/usr/local/go/src/github.com/ugorji/go/codec (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/github.com/ugorji/go/codec (from $GOPATH)
../../../../goSpace/goTestSpace/src/github.com/gin-gonic/gin/binding/default_validator.go:11:2: cannot find package "gopkg.in/go-playground/validator.v8" in any of:
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/gopkg.in/go-playground/validator.v8 (vendor tree)
/usr/local/go/src/gopkg.in/go-playground/validator.v8 (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/gopkg.in/go-playground/validator.v8 (from $GOPATH)
../../../../goSpace/goTestSpace/src/github.com/gin-gonic/gin/binding/yaml.go:12:2: cannot find package "gopkg.in/yaml.v2" in any of:
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/gopkg.in/yaml.v2 (vendor tree)
/usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/gopkg.in/yaml.v2 (from $GOPATH)
Compilation finished with exit code 1
剛剛跑一個(gè)demo看下怎么連接數(shù)據(jù)測(cè)試下,發(fā)現(xiàn)上述錯(cuò)誤,其實(shí)這個(gè)錯(cuò)誤也讓我對(duì)gopath認(rèn)識(shí)加深了,我們看看某一個(gè)錯(cuò)誤
/mouse/study/goSpace/goTestSpace/src/github.com/gin-gonic/gin/vendor/github.com/golang/protobuf/proto (vendor tree)
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/mouse/study/goSpace/goTestSpace/src/github.com/golang/protobuf/proto (from $GOPATH)
在我們引入第三方的時(shí)候,其會(huì)在三個(gè)地方區(qū)查找
1、GOROOT路徑
2、GOPATH路徑
3、在原目錄中的vendor目錄下進(jìn)行查找