Documentation
¶
Overview ¶
Package config declares the environment variables an application reads and checks them all at once before it starts. Environment variables hold deployment values and secrets only; everything else belongs in code.
Index ¶
- type AppKit
- type AppSettings
- type Declaration
- type Defaults
- type Environment
- func (environment *Environment) AppKit(defaults Defaults) AppKit
- func (environment *Environment) Check() error
- func (environment *Environment) Declarations() []Declaration
- func (environment *Environment) Invalid(name, reason string)
- func (environment *Environment) Optional(name, fallback, description string) string
- func (environment *Environment) Required(name, description string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppKit ¶
type AppKit struct {
App AppSettings
Sessions identity.SessionConfig // the application still sets Policy
MasterKey *encryption.Key // nil when APP_MASTER_KEY is missing or invalid; Check reports why
}
AppKit holds every value AppKit reads from the environment.
type AppSettings ¶
AppSettings are the application-wide values the application runs with.
func (AppSettings) Development ¶
func (settings AppSettings) Development() bool
Development reports whether APP_ENV is development.
type Declaration ¶ added in v0.10.0
type Declaration struct {
Name string
Description string
Required bool
Default string // optional variables only
}
Declaration is one variable the application reads, as declared through Required or Optional.
type Defaults ¶
type Defaults struct {
DatabasePath string // DATABASE_PATH
ListenAddress string // LISTEN_ADDRESS
Environment string // APP_ENV
}
Defaults replaces AppKit's defaults for the application-wide variables. Empty fields keep AppKit's: app.sqlite, 127.0.0.1:8080, and production.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment collects declarations. AppKit packages declare their own variables through it, and the application adds its own.
func New ¶
func New() *Environment
New starts an empty set of declarations read from the process environment.
func (*Environment) AppKit ¶
func (environment *Environment) AppKit(defaults Defaults) AppKit
AppKit declares and reads every AppKit variable. An application usually passes config.Defaults{}.
func (*Environment) Check ¶
func (environment *Environment) Check() error
Check returns every missing or invalid variable in one error. When there are none and APP_ENV is development, it logs each optional variable that uses its default.
func (*Environment) Declarations ¶ added in v0.10.0
func (environment *Environment) Declarations() []Declaration
Declarations returns every variable declared so far, in declaration order, so a command can list or ask for them without starting the application.
func (*Environment) Invalid ¶
func (environment *Environment) Invalid(name, reason string)
Invalid records a declared variable whose value cannot be used.
func (*Environment) Optional ¶
func (environment *Environment) Optional(name, fallback, description string) string
Optional declares a variable with a default and returns its value.
func (*Environment) Required ¶
func (environment *Environment) Required(name, description string) string
Required declares a variable that must be set and returns its value.