Nafeem Haque

Software Engineer

17 Dec 2023

How to Publish Go Package

All the developers that love golang, has one point in time thought about releasing his own golang package. In this blog we are going to describe step by step process on how to publish your go package.

Basic Requirements

  • Your code needs to be in a public repository.
  • Your repository should have a LICENSE file [Ex MIT,APACHE….].
  • You need to create tags with format of vX.X.X and push.
    • run git tag v0.0.1 (example version)
    • run git push origin v0.0.1 (example version)

After that you are good to go. You will be able to find your package now in pkg.go.dev. Keep in mind that you will not find your package instantly as it takes time to index. Sometimes it can take hour to days.

Good Practice

  • Write tests to cover 100% of your code.
    • You can check code coverage by adding --cover flag to your test command. For example run go test -v ./ --cover
  • Add documentation to your package.
  • Write a good Readme File.
  • Add workflows to run your tests/builds when you push.
  • Check and see how your package scores by different reporting websites such as GOREPORTCARD
  • Include different badges that expresses your project, for example build passing, report etc.
  • Show examples of how to use the package.
  • Write project description

Hope this blog will help you out to have your own golang package that other people can use.