server

package module
v1.8.10 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 13 modules, 26 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.

README

go-server

go-server is a Go module of packages for building HTTP servers and their command-line clients. Applications import it:

go get github.com/mutablelogic/go-server

Packages

Package Description
broadcaster Publishes changes, such as to the rows of a server's tables, and streams them to clients at /changes, with a client and a changes command
config Serves the server's configuration at /config.json, for its frontend: its API's prefix, its name, its version, its documentation, and its public endpoint
frontend The @mutablelogic/go-server TypeScript package, of the configuration, the broadcaster's changes, notifications and panels, for the frontends of servers built on go-server
test A HTTP test server of an API, which checks every request and response against its OpenAPI specification
pkg/cmd Command-line applications, with a server command, global flags and defaults which are kept between commands
pkg/httpserver The HTTP server, with its timeouts
pkg/httprouter The router, with cross-origin requests, and an OpenAPI specification of its paths
pkg/httprequest Reading requests: JSON, forms, queries, and files streamed from the request
pkg/httpresponse Writing responses: JSON, errors, streams with a deadline for each write, and files, with their caching and preconditions
pkg/jsonschema JSON schemas of Go types, and validating JSON with them
pkg/openapi OpenAPI specifications, and their documentation in markdown
pkg/otel OpenTelemetry tracing
pkg/logger Structured logging
pkg/tui Tables and other output for terminals
pkg/types Common types, such as files, content types and headers
pkg/version The version of a build

Building and testing

You need Go, the version in go.mod, and Make.

Target Description
make Builds the commands in cmd into build, such as build/server
make test Runs go vet, and the unit and coverage tests
make vet Runs go vet
make unit-test Runs the unit tests, with TEST_FLAGS, such as TEST_FLAGS=-v
make race-test Runs the unit tests with the race detector
make coverage-test Reports the tests' coverage, in build/coverage.txt
make tidy Runs go mod tidy
make frontend Builds the TypeScript package, with npm
make frontend-test Tests the TypeScript package
make clean Removes the build directory

Go runs with GOWORK=off, so a Go workspace doesn't change what's built. Set GOWORK to use one.

build/server runs a server with go-server's APIs, such as the broadcaster's stream of changes, with server run, and is their client, such as with server changes.

The tests run in GitHub Actions for pull requests and pushes to main on Linux, and for releases on Windows and macOS too.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd added in v1.5.6

type Cmd interface {
	// Name returns the executable name.
	Name() string

	// Description returns the application description string.
	Description() string

	// Version returns the application version string.
	Version() string

	// Context returns the lifecycle context (cancelled on SIGINT).
	Context() context.Context

	// Logger returns the structured logger.
	Logger() *slog.Logger

	// Tracer returns the OpenTelemetry tracer, or nil if OTel is not configured.
	Tracer() trace.Tracer

	// Meter returns the OpenTelemetry meter, or nil if OTel is not configured.
	Meter() metric.Meter

	// ClientEndpoint returns the HTTP endpoint URL and client options derived
	// from the global HTTP flags.
	ClientEndpoint() (string, []client.ClientOpt, error)

	// URL returns the advertised server URL, derived from the global HTTP flags. Returns
	// nil if the URL cannot be determined.
	URL() *url.URL

	// Get retrieves a default value by key. Returns nil if the key does not exist.
	Get(string) any

	// GetString retrieves a default string value by key. Returns empty string if the key
	// does not exist or the value is not a string.
	GetString(string) string

	// Set stores a default value by key and persists the store to disk.
	// Pass nil to remove a key.
	Set(string, any) error

	// Keys returns all keys in the store.
	Keys() []string

	// IsTerm returns 0 if stderr is not an interactive terminal, or the
	// width of the terminal if it is.
	IsTerm() int

	// IsDebug reports whether debug logging is enabled.
	IsDebug() bool

	// HTTPAddr returns the HTTP listen/connect address.
	HTTPAddr() string

	// HTTPPrefix returns the HTTP path prefix.
	HTTPPrefix() string

	// HTTPTimeout returns the HTTP read/write timeout.
	HTTPTimeout() time.Duration

	// WithContext returns a copy of the Cmd with the provided context.
	WithContext(context.Context) Cmd
}

Cmd provides access to the runtime context that is set up by the main entry point and passed to command Run methods.

type HTTPFileServer

type HTTPFileServer interface {
	// HandlerPath returns the route path relative to the router prefix.
	HandlerPath() string

	// HandlerFS returns the filesystem to serve.
	HandlerFS() fs.FS

	// Spec returns the OpenAPI path-item description for this
	// handler, or nil if no spec is provided.
	Spec() *openapi.PathItem
}

HTTPFileServer defines methods for static file serving handlers. When the router detects a handler that implements this interface, it uses [Router.RegisterFS] instead of [Router.RegisterFunc] so that the router prefix is correctly stripped from the request path.

type HTTPHandler

type HTTPHandler interface {
	// HandlerPath returns the route path relative to the router prefix
	// (e.g. "resource", "resource/{id}").
	HandlerPath() string

	// HandlerFunc returns the HTTP handler function.
	HandlerFunc() http.HandlerFunc

	// Spec returns the OpenAPI path-item description for this
	// handler, or nil if no spec is provided.
	Spec() *openapi.PathItem
}

HTTPHandler defines methods for HTTP handlers

type HTTPMiddleware

type HTTPMiddleware interface {
	WrapFunc(http.HandlerFunc) http.HandlerFunc
}

HTTPMiddleware defines methods for HTTP middleware

type HTTPRouter

type HTTPRouter interface {
	http.Handler

	// Spec returns the OpenAPI specification for this router.
	Spec() *openapi.Spec
}

HTTPRouter defines methods for a http router

type HTTPServer

type HTTPServer interface {
	// Spec returns the OpenAPI server entry for this instance,
	// or nil if not yet available.
	Spec() *openapi.Server
}

HTTPServer defines methods for an HTTP server instance. The router uses this interface to populate the OpenAPI spec's servers list.

Directories

Path Synopsis
Package broadcaster publishes changes, such as to the rows of a server's tables, to the channels which watch it, so a server's clients see the changes as they happen
Package broadcaster publishes changes, such as to the rows of a server's tables, to the channels which watch it, so a server's clients see the changes as they happen
cmd
Package cmd has the broadcaster's commands and flags
Package cmd has the broadcaster's commands and flags
httpclient
Package httpclient is a client of the broadcaster's HTTP API
Package httpclient is a client of the broadcaster's HTTP API
httphandler
Package httphandler has the broadcaster's HTTP API, which streams its changes to clients
Package httphandler has the broadcaster's HTTP API, which streams its changes to clients
schema
Package schema has the changes which a broadcaster publishes
Package schema has the changes which a broadcaster publishes
cmd
server command
Command server runs a HTTP server with go-server's APIs, such as the broadcaster's stream of changes, and is a client of them
Command server runs a HTTP server with go-server's APIs, such as the broadcaster's stream of changes, and is a client of them
Package config advertises a server's configuration, at /config.json, to its frontend: the path prefix of its API, its name, its version, when it was built, where the API's documentation is, and its public endpoint, when it has one
Package config advertises a server's configuration, at /config.json, to its frontend: the path prefix of its API, its name, its version, when it was built, where the API's documentation is, and its public endpoint, when it has one
pkg
cmd
httprouter
Package httprouter provides an HTTP request router with built-in cross-origin request forgery (CSRF) protection, middleware support, and OpenAPI spec generation.
Package httprouter provides an HTTP request router with built-in cross-origin request forgery (CSRF) protection, middleware support, and OpenAPI spec generation.
openapi/schema
Package schema provides Go types for the OpenAPI 3.1 specification.
Package schema provides Go types for the OpenAPI 3.1 specification.
openapi/static
Package static contains embedded static files for the OpenAPI handler.
Package static contains embedded static files for the OpenAPI handler.
provider/schema/schematest
Package schematest provides shared mock implementations of schema.Resource and schema.ResourceInstance for use in tests.
Package schematest provides shared mock implementations of schema.Resource and schema.ResourceInstance for use in tests.
tui
Package test has a HTTP test server of an API, which records every request and response, and checks them against the API's OpenAPI specification when the test ends, for the tests of go-server's packages, and of the servers which use them
Package test has a HTTP test server of an API, which records every request and response, and checks them against the API's OpenAPI specification when the test ends, for the tests of go-server's packages, and of the servers which use them

Jump to

Keyboard shortcuts

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