cmd

package
v1.6.14 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal added in v1.6.14

func IsTerminal() bool

IsTerminal reports whether os.Stderr is an interactive terminal.

func Main added in v1.6.14

func Main[T any](cmds T, description, version string) error

Main is the main entry point for all commands. It parses command-line arguments and then dispatches to the appropriate command handler.

Types

type Global added in v1.6.14

type Global struct {
	// Debug options
	Debug        bool             `name:"debug" help:"Enable debug logging"`
	Verbose      bool             `name:"verbose" help:"Enable verbose logging"`
	PrintVersion kong.VersionFlag `name:"version" help:"Print version and exit"`

	// HTTP server options
	HTTP struct {
		Prefix  string        `name:"prefix" help:"HTTP path prefix" default:"/api"`
		Addr    string        `name:"addr" env:"${ENV_NAME}_ADDR,ADDR" help:"HTTP Listen address" default:"localhost:8084"`
		Timeout time.Duration `name:"timeout" help:"HTTP server read/write timeout" default:"15m"`
		Origin  string        `` /* 202-byte string literal not displayed */
	} `embed:"" prefix:"http."`

	// Open Telemetry options
	OTel struct {
		Endpoint string `env:"OTEL_EXPORTER_OTLP_ENDPOINT" help:"Open Telemetry endpoint" default:""`
		Header   string `env:"OTEL_EXPORTER_OTLP_HEADERS" help:"OpenTelemetry collector headers"`
		Name     string `env:"OTEL_SERVICE_NAME" help:"OpenTelemetry service name" default:"${EXECUTABLE_NAME}"`
	} `embed:"" prefix:"otel."`
	// contains filtered or unexported fields
}

func (*Global) ClientEndpoint added in v1.6.14

func (g *Global) ClientEndpoint() (string, []client.ClientOpt, error)

ClientEndpoint returns the HTTP endpoint URL and client options derived from the global HTTP flags.

func (*Global) Context added in v1.6.14

func (g *Global) Context() context.Context

func (*Global) Description added in v1.6.14

func (g *Global) Description() string

func (*Global) Logger added in v1.6.14

func (g *Global) Logger() *slog.Logger

func (*Global) Name added in v1.6.14

func (g *Global) Name() string

func (*Global) Tracer added in v1.6.14

func (g *Global) Tracer() trace.Tracer

func (*Global) Version added in v1.6.14

func (g *Global) Version() string

type RegisterFunc added in v1.6.14

type RegisterFunc func(*httprouter.Router, server.Cmd) error

RegisterFunc is called after the router is created but before the server starts listening. Use it to add routes and wire up handlers.

type RunServer added in v1.6.14

type RunServer struct {
	OpenAPI bool `name:"openapi" help:"Serve OpenAPI spec at {prefix}/openapi.json" default:"true" negatable:""`

	// TLS server options
	TLS struct {
		ServerName string `name:"name" help:"TLS server name"`
		CertFile   string `name:"cert" help:"TLS certificate file"`
		KeyFile    string `name:"key" help:"TLS key file"`
	} `embed:"" prefix:"tls."`
	// contains filtered or unexported fields
}

RunServer is a general-purpose "run" command. Embed it in your CLI's command struct to get a fully functional HTTP server with logging and OTel middleware.

func (*RunServer) Register added in v1.6.14

func (s *RunServer) Register(fns ...RegisterFunc) *RunServer

Register appends fns to the list of functions called to wire up routes before the server starts. Returns the receiver for chaining.

func (*RunServer) Run added in v1.6.14

func (s *RunServer) Run(ctx *Global) error

Jump to

Keyboard shortcuts

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