/go-libs

Primary LanguageGoMIT LicenseMIT

go-libs

Blacklane's multi-module repository for Go libraries :)

It's a work in progress, everyone is welcome to help. We use GitHub Issues for bug report and requests.

Repository structure

Every folder is a library, currently we have:

  • logger: a wrapper around zerolog and compliant with our standards
  • tracking: adds UUID and other things to the context
  • x: Experimental, they are experiments or work in progress which are not ready to be recommended as a standard
    • events: An event producer and consumer abstraction and a kafka implementation. Currently a work in progress on the branch events

The maintainers of each library is defines in the CODEOWNERS file. If the library does not provide one, consider the top-level CODEOWNERS as the maintainers.

Releases and versioning

As defined by Go modules we use semantic versioning as defined by semver.

The tag for version 1.2.3 of module "my-repo/foo/rop" is "foo/rop/v1.2.3".

Commit messages, Issues and Pull Requests

They should be prefixed by the affected module, e.g.:

  • logger: release vx.y.z
  • tracking: add functions to read/set Gopher name in the context

For commit messages we follow the Go project standard as much as possible.

A rule of thumb is that it should be written so to complete the sentence "This change modifies X to _____." That means it does not start with a capital letter, is not a complete sentence, and actually summarizes the result of the change.

Requirements to download Go private modules

  • Set GOPRIVATE=github.com/blacklane/*. For details check the docs. Note that, you should avoid the Go proxy and Go sum database.
  • Ensure go get makes authenticated calls to Github. In order to do so, configure git authentication either for HTTPS or SSH

Configuring git authentication over HTTPS

Make git to use https://$GITHUB_TOKEN@github.com/ instead of https://github.com/, where GITHUB_TOKEN is your personal access token

To do so run: git config --global url.https://$GITHUB_TOKEN@github.com/.insteadOf https://github.com

Alternatively you can manually edit your ~/.gitconfig and add the following:

[url "https://YOUR_GITHUB_TOKEN@github.com/"]
	insteadOf = https://github.com/

This is the best option to be used when building a docker image, also GITHUB_TOKEN is already available on our drone

Configuring git authentication over SSH

Make git to use ssh://git@github.com/ instead of https://github.com/

To do so run: git config --global url.ssh://git@github.com/.insteadOf https://github.com/

Alternatively you can manually edit your ~/.gitconfig and add the following:

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

This is the most common for local setup as usually git authentication over SSH is already configured.

Troubleshooting

  • Ensure your git authentication is set up and working by cloning a private repo over HTTPS: git clone https://github.com/blacklane/go-libs.git

  • Ensure GOPRIVATE is set and contains github.com/blacklane/*: go env | grep GOPRIVATE

  • When building a docker image, ensure you pass GITHUB_TOKEN as a build argument: [docker|docker-build] build --build-arg GITHUB_TOKEN=$GITHUB_TOKEN