api

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api provides the REST API server and handler registration.

Index

Constants

View Source
const (
	ContextKeySubject = "auth.subject"
	ContextKeyRoles   = "auth.roles"
	ContextKeyTargets = "auth.targets"
)

Context key constants for injecting user identity into handlers.

View Source
const (
	SelfSignedCert = "api.crt"
	SelfSignedKey  = "api.key"
)

The files of the self-signed certificate in controller.pki.key_dir.

Variables

This section is empty.

Functions

func CertFingerprint added in v0.3.0

func CertFingerprint(
	c config.ServerTLS,
	keyDir string,
) (string, error)

CertFingerprint is the SHA-256 of the certificate that the API serves, as SHA256:<hex>, which a join token pins: the certificate of c, or the self-signed one in keyDir.

func TLSConfig added in v0.3.0

func TLSConfig(
	c config.ServerTLS,
	keyDir string,
	urls ...string,
) (*tls.Config, error)

TLSConfig is the server's TLS config: the certificate of c, or the self-signed certificate in keyDir, which it makes when it does not exist. A certificate that c names later replaces the self-signed one with no other change. The server reads the files again when they change, at the next handshake: a rotated certificate takes effect with no restart.

Types

type Option

type Option func(*Server)

Option is a functional option for configuring the Server.

func WithAuditStore

func WithAuditStore(
	store audit.Store,
) Option

WithAuditStore sets the audit store for audit middleware.

func WithMeterProvider

func WithMeterProvider(
	mp *sdkmetric.MeterProvider,
) Option

WithMeterProvider sets the OTEL MeterProvider for HTTP metrics. When set, the otelecho middleware routes metrics to this provider instead of the global provider.

func WithTLS added in v0.3.0

func WithTLS(
	c *tls.Config,
) Option

WithTLS makes the server serve HTTPS with c.

type Server

type Server struct {
	Echo *echo.Echo
	// contains filtered or unexported fields
}

Server implementation of the Server's API operations.

func New

func New(
	appConfig config.Config,
	logger *slog.Logger,
	opts ...Option,
) *Server

New initialize a new Server and configure an Echo server.

func (*Server) RegisterHandlers

func (s *Server) RegisterHandlers(
	handlers []func(e *echo.Echo),
)

RegisterHandlers registers a list of handlers with the Echo instance.

func (*Server) Start

func (s *Server) Start()

Start starts the Echo server on the configured host and port. An empty host binds every interface.

func (*Server) Stop

func (s *Server) Stop(
	_ context.Context,
)

Stop gracefully shuts down the Echo server. Stop asks the server to drain and returns without waiting for it.

Cancelling is what starts the drain; StartConfig.GracefulTimeout bounds how long Echo waits, and the goroutine in Start reports the outcome. A caller must not treat this returning as "every in-flight request finished" — the start command then runs the cleanups within one shutdown budget. That budget bounds the process, not this call.

The context is unused for the same reason: there is nothing here to cancel.

type StrictHandlerFunc

type StrictHandlerFunc func(ctx *echo.Context, request any) (any, error)

StrictHandlerFunc is the shape oapi-codegen's strict handlers take under Echo v5. Each generated package declares its own identical type, so a helper shared across packages cannot name any one of them. Declaring it once here gives the shared middleware a type to sit on; call sites convert to and from their own package's version, which Go permits because the underlying signatures match.

func ScopeMiddleware

func ScopeMiddleware(
	handler StrictHandlerFunc,
	tokenManager TokenValidator,
	signingKeys authtoken.Keys,
	contextKey string,
	customRoles authtoken.CustomRoles,
) StrictHandlerFunc

ScopeMiddleware validates JWT tokens and checks for required permissions.

type TokenValidator

type TokenValidator interface {
	Validate(
		tokenString string,
		keys authtoken.Keys,
	) (*authtoken.CustomClaims, error)
}

TokenValidator parses and validates JWT tokens.

Directories

Path Synopsis
Package apierr answers, in one place, which HTTP status a failed job deserves.
Package apierr answers, in one place, which HTTP status a failed job deserves.
Package ui provides the HTTP handler for serving the embedded React UI.
Package ui provides the HTTP handler for serving the embedded React UI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL