config

package
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: Apache-2.0 Imports: 14 Imported by: 44

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfigurationFile is a path to the default configuration file to
	// load, this can be changed during init()
	DefaultConfigurationFile = ""

	// DefaultGeneralPersistDir is a path to the default directory to store
	DefaultGeneralPersistDir = ""
)

Functions

func AvailableCodecs

func AvailableCodecs() (ret []string)

AvailableCodecs returns the list of registered codecs available for use

func AvailableTransports

func AvailableTransports() (ret []string)

AvailableTransports returns the list of registered transports available for use

func RegisterCodec

func RegisterCodec(codec string, registrarFunc CodecRegistrarFunc)

RegisterCodec registers a new codec with the configuration module, with a callback that can be used to validate its configuration

func RegisterConfigSection

func RegisterConfigSection(name string, creator SectionCreator)

RegisterConfigSection registers a new Section creator which will be used to create new sections that will be available via Get() in all created Config structures

func RegisterTransport

func RegisterTransport(transport string, registrarFunc TransportRegistrarFunc)

RegisterTransport registered a transport with the configuration module by providing a callback that can be used to validate the configuration

Types

type CodecRegistrarFunc

type CodecRegistrarFunc func(*Config, string, map[string]interface{}, string) (interface{}, error)

CodecRegistrarFunc is a callback that can be registered that will validate the configuration settings for a codec registered via RegisterCodec

type CodecStub

type CodecStub struct {
	Name    string `config:"name"`
	Unused  map[string]interface{}
	Factory interface{}
}

CodecStub holds an unknown codec configuration After initial parsing of configuration, these CodecStubs are turned into real configuration blocks for the codec given by their Name field

type Config

type Config struct {
	Files    []File   `config:"files"`
	General  General  `config:"general"`
	Includes []string `config:"includes"`
	Network  Network  `config:"network"`
	Stdin    Stream   `config:"stdin"`
	// Dynamic sections
	// TODO: All top level sections to use this
	Sections map[string]Section `config:",dynamic"`
}

Config holds all the configuration for Log Courier

func NewConfig

func NewConfig() *Config

NewConfig creates a new, empty, configuration structure

func (*Config) Get

func (c *Config) Get(name string) interface{}

Get returns the requested dynamic configuration entry

func (*Config) Load

func (c *Config) Load(path string, initFactories bool) (err error)

Load the configuration from the given file If initFactories is false, factories (such as codec names or transport names) are not initialised so they do not need to be built in

func (*Config) PopulateConfig

func (c *Config) PopulateConfig(config interface{}, rawConfig interface{}, configPath string) (err error)

PopulateConfig populates dynamic configuration, automatically converting time.Duration etc. Any config entries not found in the structure are moved to an "Unused" field if it exists or an error is reported if "Unused" is not available We can then take the unused configuration dynamically at runtime based on another value

func (*Config) ReportUnusedConfig

func (c *Config) ReportUnusedConfig(rawConfig map[string]interface{}, configPath string) (err error)

ReportUnusedConfig returns an error if the given configuration map is not empty. This is used to report unrecognised configuration entries. As each configuration entry is mapped into the configuration it is removed from the configuration map, so it is expected to end up empty.

type File

type File struct {
	Paths  []string `config:"paths"`
	Stream `config:",embed"`
}

File holds the configuration for a set of paths that share the same stream configuration

type General

type General struct {
	GlobalFields     map[string]interface{} `config:"global fields"`
	Host             string                 `config:"host"`
	LineBufferBytes  int64                  `config:"line buffer bytes"`
	LogFile          string                 `config:"log file"`
	LogLevel         logging.Level          `config:"log level"`
	LogStdout        bool                   `config:"log stdout"`
	LogSyslog        bool                   `config:"log syslog"`
	MaxLineBytes     int64                  `config:"max line bytes"`
	PersistDir       string                 `config:"persist directory"`
	ProspectInterval time.Duration          `config:"prospect interval"`
	SpoolSize        int64                  `config:"spool size"`
	SpoolMaxBytes    int64                  `config:"spool max bytes"`
	SpoolTimeout     time.Duration          `config:"spool timeout"`
}

General holds the general configuration

func (*General) InitDefaults

func (gc *General) InitDefaults()

InitDefaults initialises default values for the general configuration

type Network

type Network struct {
	Factory      interface{}
	AddressPools []*addresspool.Pool

	Backoff            time.Duration `config:"failure backoff"`
	BackoffMax         time.Duration `config:"failure backoff max"`
	MaxPendingPayloads int64         `config:"max pending payloads"`
	Method             string        `config:"method"`
	Rfc2782Service     string        `config:"rfc 2782 service"`
	Rfc2782Srv         bool          `config:"rfc 2782 srv"`
	Servers            []string      `config:"servers"`
	Timeout            time.Duration `config:"timeout"`
	Transport          string        `config:"transport"`

	Unused map[string]interface{}
}

Network holds network related configuration

func (*Network) InitDefaults

func (nc *Network) InitDefaults()

InitDefaults initiases default values for the network configuration

type Section

type Section interface {
	Validate() error
}

Section is implemented by external config structures that will be registered with the config package

type SectionCreator

type SectionCreator func() Section

SectionCreator creates new Section structures

type Stream

type Stream struct {
	AddHostField     bool                   `config:"add host field"`
	AddOffsetField   bool                   `config:"add offset field"`
	AddPathField     bool                   `config:"add path field"`
	AddTimezoneField bool                   `config:"add timezone field"`
	Codecs           []CodecStub            `config:"codecs"`
	DeadTime         time.Duration          `config:"dead time"`
	Fields           map[string]interface{} `config:"fields"`
}

Stream holds the configuration for a log stream

func (*Stream) InitDefaults

func (sc *Stream) InitDefaults()

InitDefaults initialises the default configuration for a log stream

type TransportRegistrarFunc

type TransportRegistrarFunc func(*Config, string, map[string]interface{}, string) (interface{}, error)

TransportRegistrarFunc is a callback that validates the configuration for a transport that was registered vua RegisterTransport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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