go-client-template

CircleCI codecov Go Reference Stability: Active

go-client-template

A template for Go command-line clients with shared configuration and telemetry.

Create a client

Create the repository through InfraOps using this template, with its final name and description. Clone it into a directory matching the repository name, then run from the clone’s root:

gh auth login
tools/init

Initialization requires Bash 4+, GNU sed, Git, the GitHub CLI, and the development tools below. It reads the name, owner, and description from the GitHub repository at origin, then updates the module path, client names, README, and badges. An empty description or a checkout directory that differs from the repository name stops initialization before any files are changed.

The script installs dependencies, formats the project, and removes tools/ and this section. It then creates an initialization branch and runs make ready, which commits, pushes, opens a pull request, and enables auto-merge.

Development

Use the Go and Ruby toolchain provided by the CI image. The development workflow also uses betteralign, golangci-lint, and RuboCop. See make help for supported commands and their prerequisites.

Initialize the shared tooling before using Make, then install dependencies and build the client:

git submodule sync && git submodule update --init
make dep
make build

Client

Run the client with the local development configuration:

./go-client-template client -config file:test/.config/client.yaml

The starter logs awesome client and exits successfully. It does not yet call an external API or configure authentication. Implement the client behavior in internal/cmd/client/ and document a working request here. The client feature verifies the initial command’s exit status and log output.

Configuration

The local configuration selects the development environment, UUID identifiers, and text logging at info level:

environment: development
id:
  kind: uuid
telemetry:
  logger:
    kind: text
    level: info

Add client-specific settings to internal/config/ and keep the sample configuration and usage documentation aligned with them.

References