执行 go get 之后,下载的内容会出现在pkg目录下,而不是src目录下,导致项目编译不通过,网上查了很久,把问题解决的过程记录如下:
1、在当前项目目录下,执行 go mod init 目录名称 指令:
D:\goproj\src\SweatSugarApi>go mod init SweatSugarApi
go: creating new go.mod: module SweatSugarApi
2.在开发环境中go build
错误: 进程退出代码 1.
C:/Program Files/Go/bin/go.exe build [D:/goproj/src/SweatSugarApi]
go: finding module for package github.com/satori/go.uuid
util\guid.go:14:2: module github.com/satori/go.uuid: Get "https://proxy.golang.org/github.com/satori/go.uuid/@v/list": dial tcp 172.217.160.113:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
3.设置下载参数和下载地址,准备go get 下载
D:\goproj\src\SweatSugarApi>set GO111MODULE=on
D:\goproj\src\SweatSugarApi>set GOPROXY=https://goproxy.io
4.执行go get命令,带@master版本号
D:\goproj\src\SweatSugarApi>go get github.com/satori/go.uuid/@master
go: downloading github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
go: github.com/satori/go.uuid master => v1.2.1-0.20181028125025-b2ce2384e17b
5.编译通过