config

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(cs Config, c any) error

Load first ensures that the config system valid and accessible. Then it loads the config into c.

func LoadConfigFromFile

func LoadConfigFromFile(filePath string, appConfig any) error

func LoadConfigFromRigel

func LoadConfigFromRigel(etcdEndpoints, configName, schemaName string, appConfig any) error

func NewRigelClient added in v0.5.0

func NewRigelClient(etcdEndpoints string) (*rigel.Rigel, error)

Types

type Config

type Config interface {
	LoadConfig(c any) error
	Check() error
	Get(key string) (string, error)

	// Watch watches for changes to a key in the storage and sends the events to the provided channel.
	// The events includes the key and the updated value.
	// events is the channel to send events when the key's value changes
	Watch(ctx context.Context, key string, events chan<- Event) error
}

Config is an interface that represents a source from which application configuration can be loaded.

type Event added in v0.6.0

type Event struct {
	Key   string
	Value string
}

Event represents a change to a key in the storage. Key is the key that was changed Value is the new value of the key

type File

type File struct {
	ConfigFilePath string
	Config         map[string]interface{}
}

func (*File) Check

func (f *File) Check() error

func (*File) Get added in v0.6.0

func (f *File) Get(key string) (string, error)

Get retrieves a value from the configuration based on the provided key. If the value is a string, it is returned as is. If the value is not a string, it is converted to a string using fmt.Sprintf and returned along with the error ValueNotStringError. If the key is not found in the configuration, an error of type KeyNotFoundError is returned.

func (*File) LoadConfig

func (f *File) LoadConfig(appConfig any) error

func (*File) Watch added in v0.6.0

func (f *File) Watch(ctx context.Context, key string, events chan<- Event) error

type KeyNotFoundError added in v0.6.0

type KeyNotFoundError struct {
	Key string
}

func (*KeyNotFoundError) Error added in v0.6.0

func (e *KeyNotFoundError) Error() string

type Rigel

type Rigel struct {
	Client        *rigel.Rigel
	SchemaName    string
	SchemaVersion int
	ConfigName    string
}

Rigel

func (*Rigel) LoadConfig

func (r *Rigel) LoadConfig(config any) error

func (*Rigel) Watch added in v0.6.0

func (r *Rigel) Watch(ctx context.Context, key string, events chan<- Event) error

type ValueNotStringError added in v0.6.0

type ValueNotStringError struct {
	Key   string
	Value interface{}
}

func (*ValueNotStringError) Error added in v0.6.0

func (e *ValueNotStringError) Error() string

Jump to

Keyboard shortcuts

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