zeus_config

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2023 License: MIT Imports: 5 Imported by: 0

README

Translate to: 简体中文

zeus-config

Zeus Config is a universal configuration management solution built on top of Viper. It simplifies the process of loading, parsing, and accessing configuration files. By integrating the Viper library, it supports multiple configuration formats such as (JSON, YAML, TOML etc.), and provides a flexible interface and methods for reading and utilizing configuration values. The package also offers additional features like validation of configuration values, setting default values, and hot-reloading, making it easier to manage and update configurations. Whether used within a single application or as a reusable library across multiple projects, this universal configuration management package ensures consistency, scalability, and maintainability. It simplifies the complexity of configuration management while enhancing the configurability and customizability of applications.

In the *_test.go files, you will find some usage examples that can help you learn how to use the package.

Support

公众号 作者

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(params *ConfigParams) (*viper.Viper, error)

New creates a new Viper object with ConfigParams and parses the config file.

Types

type Cacher

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

Cacher is used to cache the construction of an object, such as a connection. It will detect which config values are read when constructing the object. Then, when further requests are made, it will return the same object as long as the config values which were used haven't changed.

func NewCacher

func NewCacher(cfg View, newInstance NewInstanceFunc) *Cacher

NewCacher returns a cacher which uses cfg to detect relevant changes, and newInstance to construct the object when nessisary. newInstance MUST use the provided View when constructing the object.

func (*Cacher) ForceReset

func (c *Cacher) ForceReset()

ForceReset causes Cacher to forget the cached object. The next call to Get will again use newInstance to create a new object.

func (*Cacher) Get

func (c *Cacher) Get() (interface{}, error)

Get returns the cached object if possible, otherwise it calls newInstance to construct the new cached object. When Get is next called, it will detect if any of the configuration values which were used to construct the object have changed. If they have, the cache is invalidated, and a new object is constructed. If newInstance returns an error, Get returns that error and the object will not be cached or returned.

type ConfigParams

type ConfigParams struct {
	ConfigType string
	ConfigPath []string
	ConfigName string
	WatchFunc  func(fsnotify.Event)
}

type Mutable

type Mutable interface {
	Set(string, interface{})
	View
}

Mutable is a read-write view of the configuration.

type NewInstanceFunc

type NewInstanceFunc func(cfg View) (interface{}, func(), error)

NewInstanceFunc is used by the cacher to create a new value given the config. It may return an additional function to close or otherwise cleanup if ForceReset is called.

type View

type View interface {
	IsSet(string) bool
	GetString(string) string
	GetInt(string) int
	GetInt64(string) int64
	GetFloat64(string) float64
	GetStringSlice(string) []string
	GetBool(string) bool
	GetDuration(string) time.Duration
}

View is a read-only view of the configuration. New accessors from Viper should be added here.

func Sub

func Sub(v View, key string) View

Sub returns a subset of configuration filtered by the key.

Jump to

Keyboard shortcuts

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