Documentation ¶
Overview ¶
Package config provides convenience wrappers for useful standard library types easing their use in JSON and YAML config files and as flag Values for command line tools.
This allows you to Unmarshal JSON or YAML into:
type myConfig struct { Server config.URL TLS config.TLS }
and have a net/url url.URL value available as cfg.Server.URL, and a TLS configuration as cfg.TLS.Config, with the config package taking care of parsing and validation.
Index ¶
- func LoadJSON(i interface{}, filename string, required bool) error
- func LoadYAML(i interface{}, filename string, required bool) error
- type Addr
- type Duration
- type String
- type TCPAddr
- type TLS
- type TLSClientAuth
- func (auth TLSClientAuth) MarshalJSON() ([]byte, error)
- func (auth TLSClientAuth) MarshalYAML() (interface{}, error)
- func (auth *TLSClientAuth) Set(s string) error
- func (auth *TLSClientAuth) String() string
- func (auth *TLSClientAuth) UnmarshalJSON(b []byte) error
- func (auth *TLSClientAuth) UnmarshalYAML(u func(interface{}) error) error
- type TLSConfig
- type UDPAddr
- type URL
- type UnixAddr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Addr ¶
Addr is a generic network address with JSON and YAML Marshaler and Unmarshaler methods.
func (Addr) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (Addr) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*Addr) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*Addr) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type Duration ¶
Duration provides JSON Marshaling and Unmarshaling for time.Duration values. The JSON string format is that supported by the Parse() and String() methods of time.Duration, e.g., "1m30s", "100ms", etc.
func (Duration) MarshalJSON ¶
MarshalJSON satisfies json.Marshaler
func (Duration) MarshalYAML ¶
MarshalYAML satisfies yaml.Marshaler
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON satisfies json.Unmarshaler
func (*Duration) UnmarshalYAML ¶
UnmarshalYAML satisfies yaml.Unmarshaler
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is a string value which can optionally be read from an environment variable or file.
A string value beginning with "$" is replaced by the value of the environment variable named by the rest of the string. If the value starts with "/", "./", or "../", it is replaced by the contents of the file named by the path. Otherwise, the string value is used as is.
Marshaling a String marshals the original form (environment variable or file, if applicable) in all cases.
func (*String) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (*String) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*String) Set ¶
Set sets the String to the value v, expanding v if it is an environment variable or file.
func (*String) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*String) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type TCPAddr ¶
TCPAddr is an address restricted to be in the "tcp", "tcp4", or "tcp6" networks.
func (TCPAddr) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (TCPAddr) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*TCPAddr) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*TCPAddr) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type TLS ¶
TLS provides JSON and YAML Marshalers and Unmarshalers for loading values into tls.Config.
The JSON and YAML configuration format is provided by the embedded type TLSConfig.
func (TLS) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (TLS) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*TLS) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*TLS) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type TLSClientAuth ¶
type TLSClientAuth struct{ tls.ClientAuthType }
TLSClientAuth provides a convenience wrapper for tls.ClientAuthType and conversion to and from string format.
Supported string values are:
"none": tls.NoClientCert (default) "request": tls.RequestClientCert "require": tls.RequireAnyClientCert "verify": tls.VerifyClientCertIfGiven "require+verify": tls.RequireAndVerifyClientCert
func (TLSClientAuth) MarshalJSON ¶
func (auth TLSClientAuth) MarshalJSON() ([]byte, error)
MarshalJSON satisfies the json.Marshaler interface
func (TLSClientAuth) MarshalYAML ¶
func (auth TLSClientAuth) MarshalYAML() (interface{}, error)
MarshalYAML satisfies the yaml.Marshaler interface
func (*TLSClientAuth) Set ¶
func (auth *TLSClientAuth) Set(s string) error
Set satisfies the flag.Value interface.
func (*TLSClientAuth) String ¶
func (auth *TLSClientAuth) String() string
String satisfies the flag.Value interface
func (*TLSClientAuth) UnmarshalJSON ¶
func (auth *TLSClientAuth) UnmarshalJSON(b []byte) error
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*TLSClientAuth) UnmarshalYAML ¶
func (auth *TLSClientAuth) UnmarshalYAML(u func(interface{}) error) error
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type TLSConfig ¶
type TLSConfig struct { RootCAFiles []string `json:"rootCAFiles,omitempty" yaml:"rootCAFiles,omitempty"` ClientCAFiles []string `json:"clientCAFiles,omitempty" yaml:"clientCAFiles,omitempty"` ClientAuth TLSClientAuth `json:"clientAuth,omitempty" yaml:"clientAuth,omitempty"` Certificates []struct { CertFile string `json:"certFile" yaml:"certFile"` KeyFile string `json:"keyFile" yaml:"keyFile"` } `json:"certificates,omitempty" yaml:"certificates,omitempty"` }
TLSConfig contains the configuration for TLS as it appears on the JSON or YAML config. Values parsed from the config are translated and loaded into corresponding fields in tls.Config.
type UDPAddr ¶
UDPAddr is an address restricted to be in the network "udp", "udp4", or "udp6". Other networks are considered an error.
func (UDPAddr) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (UDPAddr) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*UDPAddr) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*UDPAddr) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface
type URL ¶
URL provides JSON Marshaling and Unmarshaling of URLs, internally representing them as *url.URL from net/url.
func (URL) MarshalJSON ¶
MarshalJSON satisfies json.Marshaler
func (URL) MarshalYAML ¶
MarshalYAML satisfies yaml.Marshaler
func (*URL) UnmarshalJSON ¶
UnmarshalJSON satisfies json.Unmarshaler
func (*URL) UnmarshalYAML ¶
UnmarshalYAML satisfies yaml.Unmarshaler
type UnixAddr ¶
UnixAddr is a unix-domain socket address in the "unix", "unixpacket", or "unixgram" network
func (UnixAddr) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface
func (UnixAddr) MarshalYAML ¶
MarshalYAML satisfies the yaml.Marshaler interface
func (*UnixAddr) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface
func (*UnixAddr) UnmarshalYAML ¶
UnmarshalYAML satisfies the yaml.Unmarshaler interface