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 ¶
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 ¶
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 ¶
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
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
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.