configparser

package
v0.0.0-...-984de81 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package configparser defines some default configs handler including a configparser parser with ability to update value dynamically

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyValue          = fmt.Errorf("empty strings")
	ErrInvalidFormat       = fmt.Errorf("invalid format")
	ErrInvalidOptionsMatch = fmt.Errorf("invalid options match")
)
View Source
var Standalone = NewManager()

Standalone is a singleton config manager that acts as a general manager for iris.

View Source
var TestParser = NewManager()

TestParser acts as a test config manager.

Functions

func AddSource

func AddSource(s Source)

AddSource wraps around Manager.AddSource and can be accessed via configparser.AddSource.

func Load

func Load()

Load wraps around Manager.Load and can be accessed via configparser.Load.

Types

type EnvSource

type EnvSource struct{}
var (
	TestEnvSource *EnvSource
	EnvNameRegex  = "(ENV|env)+"
)

func (*EnvSource) GetValue

func (e *EnvSource) GetValue(key string) (interface{}, error)

GetValue will get env vars with following format for config parsing: iris.option1.option2. and will returns keys as follow IRIS_OPTION1_OPTION2.

func (*EnvSource) Name

func (e *EnvSource) Name() string

type Manager

type Manager struct {
	Options map[string]*Options
	// contains filtered or unexported fields
}

Manager holds types for generic managers to generate configs.

func NewManager

func NewManager() *Manager

NewManager makes a configs manager.

func (*Manager) AddSource

func (c *Manager) AddSource(source Source)

AddSource allows users to append given configparser source to the manager.

func (*Manager) Load

func (c *Manager) Load()

Load handles configs func LoadValue directly.

func (*Manager) Register

func (c *Manager) Register(name, desc string, defaultValue interface{}) (*Options, error)

Register will add given configs to the general manager.

type Options

type Options struct {
	// Name will have format iris.option1.option2
	Name         string
	Description  string
	DefaultValue interface{}
	LoadedValue  interface{}
	Manager      *Manager

	ConfigSource Source
}

func Register

func Register(name, desc string, defaultValue interface{}) (*Options, error)

Register wraps around Manager.Register and can be accessed via configparser.Register.

func (*Options) GetBool

func (opt *Options) GetBool() bool

GetBool are a getter bool for &Options.LoadedValue.

func (*Options) GetFloat

func (opt *Options) GetFloat() float64

GetFloat are a getter float64 for &Options.LoadedValue.

func (*Options) GetInt

func (opt *Options) GetInt() int

GetInt are a getter int for &Options.LoadedValue.

func (*Options) GetString

func (opt *Options) GetString() string

GetString are a getter string for &Options.LoadedValue.

func (*Options) LoadValue

func (opt *Options) LoadValue()

LoadValue will load given values if exists, otherwise use default ones.

func (*Options) UpdateValue

func (opt *Options) UpdateValue(val interface{})

UpdateValue updates loaded value.

type Source

type Source interface {
	GetValue(key string) (interface{}, error)
	Name() string
}

Source acts as a generic type for different source of configs. ex: env, yaml, toml. refers to EnvSource for envars parsing.

Jump to

Keyboard shortcuts

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