Documentation ¶
Overview ¶
Package config is responsible for finding, parsing and verifying the application's JSON config.
Index ¶
- Constants
- Variables
- func ValidateRecursive(s Section) error
- type BaseConfig
- type BaseHTTP
- type CacheZone
- type Config
- type Getter
- type HTTP
- type Handler
- type HeaderPairs
- type HeadersRewrite
- type Location
- type Logger
- type Section
- type StringSlice
- type System
- type Upstream
- type UpstreamAddress
- type UpstreamSettings
- type VirtualHost
Constants ¶
const DefaultCacheDuration time.Duration = time.Hour
DefaultCacheDuration is the duration which an object will be cached if it is cacheable but there are no headers expiration time in its headers and there is no explicit config for this vhost/location.
const DefaultUpstreamWeight uint32 = 1
DefaultUpstreamWeight is the weight that is assigned to upstreams with no specified weight.
Variables ¶
var ErrHandlerWithNoType = errors.New("handler must have a type")
ErrHandlerWithNoType is returned when a Handler without a type is validated
Functions ¶
func ValidateRecursive ¶
ValidateRecursive validates the supplied configuration section and all of its subsections.
Types ¶
type BaseConfig ¶
type BaseConfig struct { System System `json:"system"` Logger Logger `json:"logger"` DefaultCacheType string `json:"default_cache_type"` DefaultCacheAlgorithm string `json:"default_cache_algorithm"` ApplicationID string `json:"id"` CacheZones map[string]*json.RawMessage `json:"cache_zones"` HTTP json.RawMessage `json:"http"` }
BaseConfig is part of the root configuration type.
type BaseHTTP ¶
type BaseHTTP struct { HeadersRewrite Listen string `json:"listen"` Upstreams map[string]json.RawMessage `json:"upstreams"` Servers map[string]json.RawMessage `json:"virtual_hosts"` MaxHeadersSize int `json:"max_headers_size"` IOTransferSize types.BytesSize `json:"io_transfer_size"` ReadTimeout uint32 `json:"read_timeout"` WriteTimeout uint32 `json:"write_timeout"` // Defaults for vhosts: DefaultHandlers []Handler `json:"default_handlers"` DefaultCacheZone string `json:"default_cache_zone"` AccessLog string `json:"access_log"` Logger Logger `json:"logger"` }
BaseHTTP contains the basic configuration options for HTTP.
type CacheZone ¶
type CacheZone struct { ID string Type string `json:"type"` Path string `json:"path"` StorageObjects uint64 `json:"storage_objects"` PartSize types.BytesSize `json:"part_size"` Algorithm string `json:"cache_algorithm"` BulkRemoveCount uint64 `json:"bulk_remove_count"` BulkRemoveTimeout uint64 `json:"bulk_remove_timeout"` SkipCacheKeyInPath bool `json:"skip_cache_key_in_path"` }
CacheZone contains all configuration options for cache zones.
func (*CacheZone) GetSubsections ¶
GetSubsections returns nil (CacheZone has no subsections).
type Config ¶
type Config struct { BaseConfig CacheZones map[string]*CacheZone `json:"cache_zones"` HTTP *HTTP `json:"http"` }
Config is the root configuration type. It contains representation for everything in config.json.
func Get ¶
Get returns the specified config for the daemon. Any parsing or validation errors are returned as a second parameter.
func Parse ¶
Parse handles the full parsing and validation of a specified json config file and returns a fully populated config struct. The json file is specified by the filename argument. Any parsing or validation errors are returned as a second parameter.
func (*Config) GetSubsections ¶
GetSubsections returns a slice with all the subsections of the root config.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmashalling that also implements inheritance, custom field initiation and data validation for the root config.
type Getter ¶
Getter is helper type for function which returns a config or error if the config supposed to be returned is not parsable or some other error was encountered the idea is for this to wrap either config.Get or some other way of getting and parsing the config
type HTTP ¶
type HTTP struct { BaseHTTP Upstreams []*Upstream Servers []*VirtualHost // contains filtered or unexported fields }
HTTP contains all configuration options for HTTP.
func (*HTTP) GetSubsections ¶
GetSubsections returns a slice with all the subsections of the HTTP config.
func (*HTTP) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmashalling that also implements inheritance, custom field initiation and data validation for the HTTP config.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler contains handler options.
func NewHandler ¶
func NewHandler(name string, setting json.RawMessage) *Handler
NewHandler creates a new Handler with the provided type name and settings
func (Handler) GetSubsections ¶
GetSubsections returns nil (Handler has no subsections).
func (*Handler) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmarshalling where custom stands for resetting the Settings field.
type HeaderPairs ¶
type HeaderPairs map[string]StringSlice
HeaderPairs is map between string and string or string and []string through StringSlice
func (HeaderPairs) Copy ¶
func (h HeaderPairs) Copy() HeaderPairs
Copy makes a deep copy of the HeaderPairs
type HeadersRewrite ¶
type HeadersRewrite struct { AddHeaders HeaderPairs `json:"add_headers"` SetHeaders HeaderPairs `json:"set_headers"` RemoveHeaders StringSlice `json:"remove_headers"` }
HeadersRewrite rewrites headers
func (HeadersRewrite) Copy ¶
func (h HeadersRewrite) Copy() HeadersRewrite
Copy returns a deep copy of the HeadersRewrite
type Location ¶
type Location struct { CacheZone *CacheZone CacheDefaultDuration time.Duration // contains filtered or unexported fields }
Location contains all configuration options for virtual host's location.
func (*Location) GetSubsections ¶
GetSubsections returns the ls config subsections.
func (*Location) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmashalling that also implements inheritance and custom field initiation
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger contains logger options.
func NewLogger ¶
func NewLogger(name string, settings json.RawMessage) *Logger
NewLogger creates a new Logger with the provided type name and settings
func (Logger) GetSubsections ¶
GetSubsections returns nil (Logger has no subsections).
func (*Logger) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmarshalling where custom stands for resetting the Settings field.
type StringSlice ¶
type StringSlice []string
StringSlice is a slice of string with unmarshalling powers of turning a string into a slice of strings
func (*StringSlice) UnmarshalJSON ¶
func (s *StringSlice) UnmarshalJSON(buf []byte) error
UnmarshalJSON unmarshalles StringSlice and checks that it's valid
type System ¶
type System struct { Pidfile string `json:"pidfile"` Workdir string `json:"workdir"` User string `json:"user"` }
System contains system and environment configurations.
func (System) GetSubsections ¶
GetSubsections returns nil (System has no subsections).
type Upstream ¶
type Upstream struct { ID string Balancing string `json:"balancing"` Addresses []UpstreamAddress `json:"addresses"` Settings UpstreamSettings `json:"settings"` }
Upstream contains all configuration options for an upstream group.
func (*Upstream) GetSubsections ¶
GetSubsections returns nil (CacheZone has no subsections).
type UpstreamAddress ¶
UpstreamAddress contains a single upstream URL and it's weight.
func (*UpstreamAddress) UnmarshalJSON ¶
func (addr *UpstreamAddress) UnmarshalJSON(buff []byte) error
UnmarshalJSON is a custom JSON unmarshalling which parses upstream addresses in the format "http://some.url|weight%"
type UpstreamSettings ¶
type UpstreamSettings struct { MaxConnectionsPerServer uint32 `json:"max_connections_per_server"` UseIPv4 bool `json:"use_ipv4"` UseIPv6 bool `json:"use_ipv6"` ResolveAddresses bool `json:"resolve_addresses"` }
UpstreamSettings contains all possible upstream settings.
func GetDefaultUpstreamSettings ¶
func GetDefaultUpstreamSettings() UpstreamSettings
GetDefaultUpstreamSettings returns some sane dafault settings for upstreams
type VirtualHost ¶
type VirtualHost struct { Location Locations []*Location // contains filtered or unexported fields }
VirtualHost contains all configuration options for virtual hosts. It redefines some of the baseLocation fields to use the correct types.
func (*VirtualHost) GetSubsections ¶
func (vh *VirtualHost) GetSubsections() []Section
GetSubsections returns the vhost config subsections.
func (*VirtualHost) String ¶
func (vh *VirtualHost) String() string
func (*VirtualHost) UnmarshalJSON ¶
func (vh *VirtualHost) UnmarshalJSON(buff []byte) error
UnmarshalJSON is a custom JSON unmashalling that also implements inheritance and custom field initiation
func (*VirtualHost) Validate ¶
func (vh *VirtualHost) Validate() error
Validate checks the virtual host config for logical errors.