go test进行单元测试提示undefined
原因:test只会对当前文件进行编译测试,外部的go不会编译
解决方式1:单元测试用到其他go文件中的函数、结构体、变量等,需要在go test命令后面再加上引用的文件 如:go test -v union_tets.go security.go
解决方式2:对整个目录进行单元测试
directory prefix . does not contain main module or its selected dependencies
原因
解决方式:在终端中执行 go mod init 目录/文件名 生成go.mod文件即可
go get , go install, go mod 出现timeout超时失败
原因:未使用国内代理
解决方式:
set GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
# 设置不走 proxy 的私有仓库,多个用逗号相隔
go env -w GOPRIVATE=*.corp.example.com
go get -u gorm.io/gorm