infrapi/lib

Opinionated Go building blocks shared by InfraPI services. Each package covers one concern - configuration, serving, calling, authenticating, logging, tracing, errors - and they are designed to be used together from the same AppConfig.

Where to start#

PageWhat it covers
Getting startedAdd the dependency, write a dotenv file, serve an API group and call another service.
DevelopmentThe quality gate, building these docs, and the repository layout.

Install with go get github.com/infrapi/lib (Go 1.26.7 or later).

Packages#

PackageImport pathWhat it does
apigithub.com/infrapi/lib/pkg/apiThe URL layout every service exposes, /apis/{name}.{domain}/{version}/namespaces/{namespace}/{resource}, shared by server, client and auth.
authgithub.com/infrapi/lib/pkg/authAuthenticates requests against an upstream authentication service’s /oauth2/userinfo endpoint, with an in-memory cache, as a gin middleware.
clientgithub.com/infrapi/lib/pkg/clientResty-based client of the APIs server exposes, with TLS/mTLS, retry and hedging.
configgithub.com/infrapi/lib/pkg/configReads a dotenv file, validates values, exposes a typed AppConfig.
errorsgithub.com/infrapi/lib/pkg/errorsRFC 9457 application error with an HTTP status, a cause, a remediation hint, a stable code and an explicit retryable flag.
listenergithub.com/infrapi/lib/pkg/listenerOpens the service socket, TCP or systemd socket activation.
loggergithub.com/infrapi/lib/pkg/loggerBuilds the *logger.Logger a service’s own code logs through, from the same AppConfig log level and format, with one shared set of conventions.
servergithub.com/infrapi/lib/pkg/servergin.Engine pre-wired with CORS, trusted proxies, Prometheus metrics, a span per request, generated OpenAPI docs or the service’s own contracts — enforced on every request — and rendering an errors.Error as application/problem+json.
tofugithub.com/infrapi/lib/pkg/tofuDrives any OpenTofu provider plugin and resource type, and applies a declarative set of providers and resources on top.
tracinggithub.com/infrapi/lib/pkg/tracingSends the traces over OTLP (HTTP or gRPC), from the INFRAPI_TRACING_* keys.
vaultgithub.com/infrapi/lib/pkg/vaultWraps vault-client-go with TLS/mTLS, retry, AppRole/token login, and an opinionated KV v2 and PKI surface.