config

package
v1.8.15 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 18 Imported by: 4 modules, 4 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 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

Index

Constants

View Source
const (
	// Path is where the configuration is served, which is beside the
	// frontend, rather than beneath the API's prefix, which it says
	Path = "/config.json"

	// Tag is the configuration's tag, which a server with tag groups adds to
	// one of them, as Redoc doesn't show a tag which isn't in a group
	Tag = "Config"
)

Variables

This section is empty.

Functions

func PublicEndpoint

func PublicEndpoint(endpoint *url.URL) string

PublicEndpoint returns the URL, when it's https, as it is when the server was given its public name, without a slash at its end, or none

func RegisterHandler

func RegisterHandler(router *httprouter.Router, config Config, options ...Opt) error

RegisterHandler registers the configuration with the router, at Path, with Tag, and the modules' sections, which are documented by their types

Types

type Config

type Config struct {
	Prefix  string `json:"prefix" help:"Path prefix of the API, such as /api"`
	Name    string `json:"name,omitempty" help:"Name of the server, such as its command"`
	Version string `json:"version,omitempty" help:"Version of the server"`

	// When the server was built, so its frontend knows it's been rebuilt,
	// and offers to refresh the page, even when its version is the same,
	// such as while it's developed
	Build   string `json:"build,omitempty" help:"When the server was built" format:"date-time"`
	OpenAPI string `json:"openapi,omitempty" help:"Path of the API's documentation, when it's served"`

	// The server's public endpoint, such as https://example.com/api, when it
	// was given its public name, such as that of a proxy it's behind, with
	// --tls.name, so it's https, or none, when it wasn't, as its own URL is
	// then its listen address, which its frontend can't always reach
	Endpoint string `` /* 142-byte string literal not displayed */

	// What the server's modules, such as its packages, say of themselves,
	// by their names, such as what they can do, which RegisterHandler sets
	// from WithSection and WithSectionFunc, each time it's served
	Modules map[string]any `json:"modules,omitempty" help:"What the server's modules say of themselves, by their names, such as what they can do"`
}

Config is a server's configuration, which its frontend reads from /config.json, so it knows where the API is

func New

func New(ctx server.Cmd, router *httprouter.Router, openapi bool) Config

New returns the configuration of the server which the command runs, with the router's prefix, the command's name and version, when it was built, when it's known, the path of the API's documentation, when openapi is true, as it's served, and the command's URL, as its public endpoint, when it's https. It's called once the server's URL is known, such as when its routes are registered.

type Opt added in v1.8.7

type Opt func(*opts) error

Opt is an option of the configuration's handler, such as a module's section

func WithSection added in v1.8.7

func WithSection[T any](name string, value T) Opt

WithSection adds a module's section to the configuration, under modules, by its name, such as credential, with its value, such as what the module can do, which the API's documentation describes, by its type

func WithSectionFunc added in v1.8.12

func WithSectionFunc[T any](name string, fn func() T) Opt

WithSectionFunc adds a module's section to the configuration, as WithSection does, whose value the function returns each time the configuration is served, such as the module's status, which changes while the server runs. It's called concurrently, as requests are.

Jump to

Keyboard shortcuts

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