config

package
v0.0.0-...-8cfe5f7 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: GPL-3.0 Imports: 7 Imported by: 5

Documentation

Overview

Package config handles everything related to runtime-configuration.

Three configuration sources are supported. In order of ascending priority: configuration file, environment variables, command line arguments.

Index

Constants

View Source
const (
	LOG_OFF   = "off"
	LOG_WARN  = "warn"
	LOG_INFO  = "info"
	LOG_DEBUG = "debug"
	LOG_TRACE = "trace"
)
View Source
const (
	ENV_VAR_PREFIX = "__TILO_"
	CLI_VAR_PREFIX = "--"
)

Variables

This section is empty.

Functions

func FromCommandLineParams

func FromCommandLineParams(args []string) (rawConf, []string, error)

Read a configuration from command line parameters.

func FromEnvironment

func FromEnvironment(env []string) rawConf

Read a configuration from environment-compatible key=value pairs.

func FromFile

func FromFile(configFile string) (rawConf, error)

Read configuration from a config file.

func RegisterBackend

func RegisterBackend(bcp BackendConfig)

Types

type BackendConfig

type BackendConfig interface {
	// The name of the corresponding backend.
	BackendName() string
	// The items accepted by this parser
	AcceptedItems() []*Item
}

type Item

type Item struct {
	InFile string
	InArgs string
	InEnv  string
	Value  string
}

TODO: Add Description field for help messages?

type Opts

type Opts struct {
	// The location of the configuration file.
	ConfFile Item
	// The protocol to use for server communication.
	Protocol Item
	// The name of the request socket file.
	Socket Item
	// The server's backend
	Backend Item
	// Determines the amount of additional log output.
	LogLevel Item
}

Configuration parameters.

func GetConfig

func GetConfig(args []string, env []string) (*Opts, []string, error)

func (*Opts) AcceptedItems

func (c *Opts) AcceptedItems() []*Item

func (*Opts) AsEnvKeyValue

func (c *Opts) AsEnvKeyValue() []string

Emit the configuration in a format suitable as environment variables.

func (*Opts) ConfigDir

func (c *Opts) ConfigDir() string

func (*Opts) MergeIntoEnv

func (c *Opts) MergeIntoEnv(env []string) []string

Take a list of environment-compatible key=value pairs and add tilo-options.

func (*Opts) ShouldLogAny

func (c *Opts) ShouldLogAny() bool

func (*Opts) ShouldLogDebug

func (c *Opts) ShouldLogDebug() bool

func (*Opts) ShouldLogInfo

func (c *Opts) ShouldLogInfo() bool

func (*Opts) ShouldLogTrace

func (c *Opts) ShouldLogTrace() bool

func (*Opts) ShouldLogWarnings

func (c *Opts) ShouldLogWarnings() bool

func (*Opts) SocketDir

func (c *Opts) SocketDir() string

Jump to

Keyboard shortcuts

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