go import導(dǎo)入的理解

在使用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)行查找

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容