脚本宝典收集整理的这篇文章主要介绍了

Semantic Versioning on Private Library Package for Golang 1.13

脚本宝典小编觉得挺不错的,现在分享给大家,也给大家做个参考,希望能帮助你少写一行代码,多一份安全和惬意。

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

Configure 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.

Use Private Library Package For Versioning

  • Make sure your GOPRIVATE and GOPROXY works as well as we expect.

    GOPRIVATE=foo.bar.com
    GOPROXY=https://goproxy.io,direct

    Be careful :

    • GOPRIVATE=foo.bar.com means : all Packages from foo.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 sure direct section was placed EXACTLY at the end of this line. For now, our configuration means : If go build can't find package foo.bar.com/group/project via https://goproxy.io/group/project Then it will try to find it via http://foo.bar.com/group/project
  • Access your git repo

    • Use SSH instead of HTTP

      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.
  • Pull the Trigger

    • Import library package and use it

      go get -u -v foo.bar.com/group/project@v1.0.0
      go build .

Migrate to Docker

  • Use key pair for Docker build

    ssh-keygen -f /path/to/build-key

    Change your docker file

    COPY/path/to/build-key` ~/.ssh/id_rsa

    Setup SSH public key /path/to/build-key.pub on gitlab.

总结

以上是脚本宝典为你收集整理的

Semantic Versioning on Private Library Package for Golang 1.13

全部内容,希望文章能够帮你解决

Semantic Versioning on Private Library Package for Golang 1.13

所遇到的程序开发问题,欢迎加入QQ群277859234一起讨论学习。如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典网站推荐给程序员好友。 本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。

80%的人都看过