JavaGogo get xxximportgo getGoJavaGoGo~/.bash_profile#GOROOT,用pkg安装无需配置export GOROOT=/usr/local/go#GOPATHexport GOPATH="/Users/wjy/go:/Users/wjy/MyProjects/golang_projects"# GOBIN#export PATH=$PATH:/Users/wjy/go/bin复制代码
/usr/local/go:go installgo installGOBINshellgo buildgo installgo buildgo installgo buildgo installbin$GOPATH/bin只要GOPATH配置正确,导包就不会有问题。go的项目路径要求是这样的
GOPATH |--bin (go install命令编译后的可执行文件存放目录) |--src |__项目A(github.wujiuye.blog) |--app.go(main.go,当前路径下执行go build与go install命令编译项目) |--model(一些结构体的定义) |--service(service层) |--controller |--dao |--common(一些组件类) |__项目B复制代码
GOPATHGOPATHsrcGOPATHsrcbinpkgbinggo installgo get xxxxmodeluser.goserviceimport 项目A/modelmodelmodelpackage service
import github.wujiuye.blog/model
func UserTest(){
var user model.User = &model.User{}
}复制代码go get xxxpackage golang.org/x/sys/unix: unrecognized import path "golang.org/x/sys/unix" (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)复制代码