config

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type C

type C struct {
	Settings map[interface{}]interface{}
	// contains filtered or unexported fields
}

func NewC

func NewC(l *logrus.Logger) *C

func (*C) CatchHUP

func (c *C) CatchHUP(ctx context.Context)

CatchHUP will listen for the HUP signal in a go routine and reload all configs found in the original path provided to Load. The old settings are shallow copied for change detection after the reload.

func (*C) Get

func (c *C) Get(k string) interface{}

func (*C) GetBool

func (c *C) GetBool(k string, d bool) bool

GetBool will get the bool for k or return the default d if not found or invalid

func (*C) GetDuration

func (c *C) GetDuration(k string, d time.Duration) time.Duration

GetDuration will get the duration for k or return the default d if not found or invalid

func (*C) GetInt

func (c *C) GetInt(k string, d int) int

GetInt will get the int for k or return the default d if not found or invalid

func (*C) GetMap

func (c *C) GetMap(k string, d map[interface{}]interface{}) map[interface{}]interface{}

GetMap will get the map for k or return the default d if not found or invalid

func (*C) GetString

func (c *C) GetString(k, d string) string

GetString will get the string for k or return the default d if not found or invalid

func (*C) GetStringSlice

func (c *C) GetStringSlice(k string, d []string) []string

GetStringSlice will get the slice of strings for k or return the default d if not found or invalid

func (*C) GetUint32

func (c *C) GetUint32(k string, d uint32) uint32

GetUint32 will get the uint32 for k or return the default d if not found or invalid

func (*C) HasChanged

func (c *C) HasChanged(k string) bool

HasChanged checks if the underlying structure of the provided key has changed after a config reload. The value of k in both the old and new settings will be serialized, the result of the string comparison is returned. If k is an empty string the entire config is tested. It's important to note that this is very rudimentary and susceptible to configuration ordering issues indicating there is change when there actually wasn't any.

func (*C) InitialLoad

func (c *C) InitialLoad() bool

InitialLoad returns true if this is the first load of the config, and ReloadConfig has not been called yet.

func (*C) IsSet

func (c *C) IsSet(k string) bool

func (*C) Load

func (c *C) Load(path string) error

Load will find all yaml files within path and load them in lexical order

func (*C) LoadString

func (c *C) LoadString(raw string) error

func (*C) RegisterReloadCallback

func (c *C) RegisterReloadCallback(f func(*C))

RegisterReloadCallback stores a function to be called when a config reload is triggered. The functions registered here should decide if they need to make a change to the current process before making the change. HasChanged can be used to help decide if a change is necessary. These functions should return quickly or spawn their own go routine if they will take a while

func (*C) ReloadConfig

func (c *C) ReloadConfig()

func (*C) ReloadConfigString

func (c *C) ReloadConfigString(raw string) error

Jump to

Keyboard shortcuts

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