config

package
v0.0.0-...-7f35424 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

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

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

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

type KeyNotFoundError

type KeyNotFoundError struct {
	Key string
}

func (*KeyNotFoundError) Error

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

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

type ValueNotStringError

type ValueNotStringError struct {
	Key   string
	Value interface{}
}

func (*ValueNotStringError) Error

func (e *ValueNotStringError) Error() string

Jump to

Keyboard shortcuts

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