go module安装本地离线包

本地有go模块源码,但没办法使用go get,go install等方式直接安装,解决办法:

1.在本地项目目录下新建external文件夹(文件夹名随意)

2.修改项目的go.mod文件,(1)先在require字段填写需要的包和版本号;(2)在最底部新增replace字段

replace (
	flume v1.2.3 => ./extenal/flume
	genitus v1.2.3 => ./extenal/genitus
	git.apache.org/thrift.git v1.2.3 => ./extenal/git.apache.org/thrift.git
	github.com/DeanThompson/ginpprof v1.2.3 => ./extenal/github.com/DeanThompson/ginpprof
	github.com/aws v1.2.3 => ./extenal/github.com/aws
	github.com/jmespath/go-jmespath v1.2.3 => ./extenal/github.com/jmespath/go-jmespath
	//github.com/jsonschema v1.2.3 => ./extenal/github.com/jsonschema
	github.com/linkedin/goavro v1.2.3 => ./extenal/github.com/linkedin/goavro
	github.com/minio/blake2b-simd v1.2.3 => ./extenal/github.com/minio/blake2b-simd
	github.com/qri-io v1.2.3 => ./extenal/github.com/qri-io
	github.com/satori/go.uuid v1.2.3 => ./extenal/github.com/satori/go.uuid
	github.com/shirou/gopsutil v1.2.3 => ./extenal/github.com/shirou/gopsutil
	google.golang.org/grpc v1.2.3 => ./extenal/google.golang.org/grpc
)

本质就是让module管理模块根据.mod文件去指定文件夹下寻找对应的go包

你可能感兴趣的:(Go,golang,github,git)