What we need?
- Golang version 1.13 or above
-
GOPRIVATE
introduced to go module since 1.13 - multi section of
GOPROXY
introduced to go module since 1.13
-
- Running Gitlab
- Certainly, We need it host our private code. I assumed your gitlab running happily at http://foo.bar.com
go.mod
file for Library Package
- Init a package named
group/project
go mod init foo.bar.com/group/project
- Write some bugs with few lines of functional code, then commit and push.
- Release your package with Semantic Version
git tag -a v1.0.0 -m "release v1.0.0 for semantic version testing"
git push --tags
- Checkout your hard work on Gitlab.
- Make sure your
GOPRIVATE
andGOPROXY
works as well as we expect.GOPRIVATE=foo.bar.com
GOPROXY=https://goproxy.io,direct
-
GOPRIVATE=foo.bar.com
means : all Packages fromfoo.bar.com
was private package, go build will skip checksum cuz we trust our teammate. lol. - You may have your own setting of
GOPROXY
, always make suredirect
section was placed EXACTLY at the end of this line. For now, our configuration means : If go build can't find packagefoo.bar.com/group/project
viahttps://goproxy.io/group/project
Then it will try to find it viahttp://foo.bar.com/group/project
-
- Access your git repo
- Use
SSH
instead ofHTTP
git config --global url."git@foo.bar.com:".instead of "http://foo.bar.com/"
- Setup
SSH
public key on gitlab, You can easily make it via Google.
- Use
- Pull the Trigger
- Import library package and use it
go get -u -v foo.bar.com/group/project@v1.0.0
go build -v .
- Import library package and use it
- Use key pair for Docker build
ssh-keygen -f /path/to/build-key
COPY
/path/to/build-key` ~/.ssh/id_rsaSSH
public key/path/to/build-key.pub
on gitlab.
推荐阅读
- 【golang】leetcode中级-字母异位词分组&无重复字符的最长子串
- 彻底理解Golang Map
- kratos线上开源年会它来啦~
- 深入浅出 Golang 资源嵌入方案(go-bindata篇)
- 深入浅出 Golang 资源嵌入方案(前篇)
- golang 经典案例总结
- Go实战 | 基于有向无环图的并发执行流的实现
- Golang 数组和切片
- Go JSON编码与解码()
- golang map基础知识