Categorygithub.com/puppetlabs/go-libs
module
0.4.0
Repository: https://github.com/puppetlabs/go-libs.git
Documentation: pkg.go.dev

# README

go-libs

This repository is intended as a resource for common Go code. It is hoped that the libraries provided can be used across projects to solve common problems, boost efficiency, and improve standards across the board.

Feel free to open a pull request or suggest improvements.

Go Report Card

Libraries Provided

LibraryDescription
HTTP Service client library
HTTP Service generation
TLS Certificate generation library
TLS certificate generation
Viper config loading
ConcurrencyConcurrency provides helpers for creating multi-threaded applications

Make Targets

TargetDescription
install-toolsInstalls development tools, such as a compiler daemon and formatting utilities
formatRuns formatting utilities
lintRuns linters
testRuns unit tests
generate-certRuns an interactive script. This script will write a new TLS certificate and private key to disk for the prompted cn and DNS name(s). The CA certificate may also be written to disk depending on the answers to the prompted for questions.
generate-serviceRuns an interactive script. This script will prompt the user for input on service name, directory, listening interface(optional)/port, whether HTTPS is required(certs will be auto generated to begin with), whether rate limiting, whether a readiness check is requited, whether metrics are required and whether cors is enabled. Based on the output of this a new service will be generated to the target directory with it's own Makefile, go dependencies, dockerfile and docker compose file. A hello world handler will be provided to get going. These will be ready to use out of the box
allBuilds the code after linting it. Various sub targets exist which are run as part of make all.

Generated Service

After running the generate-service make target the service will exist in the target directory. The targets below are some things which can be done post generation of a service:

TargetDescription
runRuns the service locally.
run-hotRuns the service locally in a hot-reloading mode using the CompileDaemon
devRuns the service via Docker Compose
imageBuilds the Docker image

Generated Service Code

Code will be generated into the directory specified upon running the script. A main.go file will exist under the cmd directory, and a packages directory will exist containing config and handlers. The code under the pkg directory will need edited to supplement configuration and to add any new handlers. N.B. See the config package for details on how to tag config and use nested structs.

Linting and Formatting

This project uses the linter aggregator golangci-lint.

Currently, golangci-lint cannot be reliably installed as a Go package. It should be installed using an alternative method, such as Homebrew.

From the project root, run:

make install-tools to install development tools.

make format to format all Go files in accordance with linter standards.

make lint to run the linters.

To Do

  • Create a workstack — there are quite a few things could go in here, such as workers

# Packages

No description provided by the author
No description provided by the author