config

package
v0.0.0-...-fd00b2c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConnectionRetryMaxInterval indicates the maximum interval to retry icecast
	// connections
	ConnectionRetryMaxInterval = time.Second * 2
	// ConnectionRetryMaxElapsedTime indicates how long to try retry before
	// erroring out completely. Set to 0 means it never errors out
	ConnectionRetryMaxElapsedTime = time.Second * 0
)
View Source
const (
	// DatabaseRetryMaxInterval indicates the maximum interval between database
	// call retries after an error occurs
	DatabaseRetryMaxInterval = time.Second * 5
	// DatabaseRetryMaxElapsedTime indicates how long to try again before
	// erroring out. Set to 0 means it never errors out
	DatabaseRetryMaxElapsedTime = time.Second * 0
)

Variables

This section is empty.

Functions

func NewConnectionBackoff

func NewConnectionBackoff() *backoff.ExponentialBackOff

NewConnectionBackoff returns a new backoff set to the intended configuration for local connection retrying, for connections going to non-local addresses don't use this

func NewDatabaseBackoff

func NewDatabaseBackoff() backoff.BackOff

NewDatabaseBackoff returns a new backoff set to the intended configuration for database retrying

func NewRand

func NewRand(lock bool) *rand.Rand

NewRand returns a fresh *rand.Rand seeded with either a crypto random seed or the current time if that fails to succeed

func Value

func Value[T any](cfg Config, fn func(Config) T) func() T

func Values

func Values[T1, T2 any](cfg Config, fn func(Config) (T1, T2)) func() (T1, T2)

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is a type-safe wrapper around the config type

func Load

func Load(r io.Reader) (Config, error)

Load loads a configuration file from the reader given, it expects TOML as input

func LoadFile

func LoadFile(filenames ...string) (Config, error)

LoadFile loads a configuration file from the filename given

func (Config) Conf

func (c Config) Conf() config

Conf returns the configuration stored inside

NOTE: Conf returns a shallow-copy of the config value stored inside; so do not edit

any slices or maps that might be inside

func (Config) LoadAndUpdate

func (c Config) LoadAndUpdate(filenames ...string) error

func (*Config) OnReload

func (c *Config) OnReload(cb func())

func (Config) Save

func (c Config) Save(w io.Writer) error

Save writes the configuration to w in TOML format

func (Config) StoreConf

func (c Config) StoreConf(new config)

StoreConf stores the configuration passed

func (Config) TriggerReload

func (c Config) TriggerReload()

type Duration

type Duration time.Duration

Duration is a time.Duration that supports Text(Un)Marshaler

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Loader

type Loader func() (Config, error)

Loader is a typed function that returns a Config, used to pass in a pre-set Load or LoadFile call from a closure

Jump to

Keyboard shortcuts

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