項(xiàng)目 go run main.go
時(shí)報(bào)錯(cuò)
go env
查看環(huán)境
如果要用 gopath 模式 引入包 從src目錄下開始引入 需要關(guān)閉 go mod 模式
export GO111MODULE=off
../github.com/go-playground/universal-translator/errors.go:7:2: cannot find package "github.com/go-playground/locales" in any of:
/usr/local/go/src/github.com/go-playground/locales (from $GOROOT)
/Users/jerryzhb/go/src/github.com/go-playground/locales (from $GOPATH)
../github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/Users/jerryzhb/go/src/github.com/golang/protobuf/proto (from $GOPATH)
../github.com/go-playground/validator/baked_in.go:19:2: cannot find package "github.com/leodido/go-urn" in any of:
/usr/local/go/src/github.com/leodido/go-urn (from $GOROOT)
/Users/jerryzhb/go/src/github.com/leodido/go-urn (from $GOPATH)
../github.com/gin-gonic/gin/logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
/usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT)
/Users/jerryzhb/go/src/github.com/mattn/go-isatty (from $GOPATH)
../github.com/gin-gonic/gin/binding/msgpack.go:14:2: cannot find package "github.com/ugorji/go/codec" in any of:
/usr/local/go/src/github.com/ugorji/go/codec (from $GOROOT)
/Users/jerryzhb/go/src/github.com/ugorji/go/codec (from $GOPATH)
../github.com/gin-gonic/gin/binding/yaml.go:12:2: cannot find package "gopkg.in/yaml.v2" in any of:
/usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
/Users/jerryzhb/go/src/gopkg.in/yaml.v2 (from $GOPATH)
如果使用go mod 模式
export GO111MODULE=on
并且在目錄下執(zhí)行 go mod init
目錄下產(chǎn)生兩個(gè)文件
go.mod
go.sum
否則就會(huì)報(bào)錯(cuò)
main.go:15:2: package tinybg/conf is not in GOROOT (/usr/local/go/src/tinybg/conf)
main.go:16:2: package tinybg/utils is not in GOROOT (/usr/local/go/src/tinybg/utils)