config

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2015 License: GPL-3.0 Imports: 16 Imported by: 32

Documentation

Overview

Package config is responsible for finding, parsing and verifying the application's JSON config.

Index

Constants

View Source
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.

View Source
const DefaultUpstreamWeight uint32 = 1

DefaultUpstreamWeight is the weight that is assigned to upstreams with no specified weight.

Variables

View Source
var ErrHandlerWithNoType = errors.New("handler must have a type")

ErrHandlerWithNoType is returned when a Handler without a type is validated

Functions

func ValidateRecursive

func ValidateRecursive(s Section) error

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"`
	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"`
	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

func (cz *CacheZone) GetSubsections() []Section

GetSubsections returns nil (CacheZone has no subsections).

func (*CacheZone) Validate

func (cz *CacheZone) Validate() error

Validate checks a CacheZone config section for errors.

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

func Get() (*Config, error)

Get returns the specified config for the daemon. Any parsing or validation errors are returned as a second parameter.

func Parse

func Parse(filename string) (*Config, error)

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

func (c *Config) GetSubsections() []Section

GetSubsections returns a slice with all the subsections of the root config.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(buff []byte) error

UnmarshalJSON is a custom JSON unmashalling that also implements inheritance, custom field initiation and data validation for the root config.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the root config for errors.

type Getter

type Getter func() (*Config, error)

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

func (h *HTTP) GetSubsections() []Section

GetSubsections returns a slice with all the subsections of the HTTP config.

func (*HTTP) UnmarshalJSON

func (h *HTTP) UnmarshalJSON(buff []byte) error

UnmarshalJSON is a custom JSON unmashalling that also implements inheritance, custom field initiation and data validation for the HTTP config.

func (*HTTP) Validate

func (h *HTTP) Validate() error

Validate checks the HTTP config for logical errors.

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

func (h Handler) GetSubsections() []Section

GetSubsections returns nil (Handler has no subsections).

func (*Handler) UnmarshalJSON

func (h *Handler) UnmarshalJSON(buff []byte) error

UnmarshalJSON is a custom JSON unmarshalling where custom stands for resetting the Settings field.

func (Handler) Validate

func (h Handler) Validate() error

Validate checks a Handler config section config for errors.

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

func (ls *Location) GetSubsections() []Section

GetSubsections returns the ls config subsections.

func (*Location) String

func (ls *Location) String() string

func (*Location) UnmarshalJSON

func (ls *Location) UnmarshalJSON(buff []byte) error

UnmarshalJSON is a custom JSON unmashalling that also implements inheritance and custom field initiation

func (*Location) Validate

func (ls *Location) Validate() error

Validate checks the virtual host location config for logical errors.

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

func (l Logger) GetSubsections() []Section

GetSubsections returns nil (Logger has no subsections).

func (*Logger) UnmarshalJSON

func (l *Logger) UnmarshalJSON(buff []byte) error

UnmarshalJSON is a custom JSON unmarshalling where custom stands for resetting the Settings field.

func (Logger) Validate

func (l Logger) Validate() error

Validate checks a Logger config section config for errors.

type Section

type Section interface {
	Validate() error
	GetSubsections() []Section
}

Section defince the methods each config section has to implement

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

func (s System) GetSubsections() []Section

GetSubsections returns nil (System has no subsections).

func (System) Validate

func (s System) Validate() error

Validate checks a System config section config for errors.

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

func (cz *Upstream) GetSubsections() []Section

GetSubsections returns nil (CacheZone has no subsections).

func (*Upstream) Validate

func (cz *Upstream) Validate() error

Validate checks a CacheZone config section for errors.

type UpstreamAddress

type UpstreamAddress struct {
	URL    *url.URL
	Weight uint32
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL