Documentation ¶
Overview ¶
Package config implements the catena server configuration. The Config object uses tags to handle reasonable defaults and reading configurations from the environment. It can also be loaded from a YAML or JSON file or modified from a urifave CLI context. File configurations can be looked up with a search path that checks standard linux configuration locations. This ensures full flexibility in configuration for development and production environments, while also being overkill for the job.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶
func Find() (paths []string)
Find searches for configuration files named catena.[json,yaml] in the current directory, then in the user config dir named ~/.config/catena/config.[json,yaml] and finally in /etc/catena/config.[json,yaml] -- it returns all paths that it finds without error but does not guarantee that these configuration files are readable. Note that the paths are returned in priority order, so most callers will load the files in reverse order.
Types ¶
type Config ¶
type Config struct { Domain string `default:"localhost" env:"CATENA_DOMAIN"` Addr string `default:"127.0.0.1" env:"CATENA_BIND_ADDR"` Port uint16 `default:"8888" env:"CATENA_PORT"` NoTLS bool `env:"CATENA_NO_TLS"` DBURL string `env:"DATABASE_URL"` Routes struct { RedirectTrailingSlash bool `default:"true"` RedirectFixedPath bool `default:"true"` HandleMethodNotAllowed bool `default:"true"` } ReadTimeout time.Duration `default:"10s" env:"CATENA_READ_TIMEOUT"` WriteTimeout time.Duration `default:"20s" env:"CATENA_WRITE_TIMEOUT"` IdleTimeout time.Duration `default:"5m" env:"CATENA_IDLE_TIMEOUT"` }
Config defines the required configuration for the Catena server.
func New ¶
New creates a new configuration object with specified defaults and any values loaded from the environment. If the config object is improperly defined or it cannot parse the values from the environment it will return an error.
func (Config) BindAddr ¶
BindAddr returns the bind address and port for the http server to listen on.
func (Config) DumpFile ¶
DumpFile writes the configuration into the specified file using the extension to determine the serialization format.
func (Config) Endpoint ¶
Endpoint returns the human readable endpoint using either the domain or the bind addr with the correct protocol and port if required.
func (Config) LoadFile ¶
LoadFile updates the configuration from the specified file without modifying the original configuration (makes a copy).
func (Config) LoadSystem ¶
LoadSystem loads the system configurations discovered using Find() in reverse order, maintaining the Find() priority. E.g. it first loads from /etc/catena/config.yaml then from the user configuration, then the local directory, etc. Like LoadFile() this method does not modify the original and instead makes a copy.