configparser

package
v0.0.0-...-99e36ab Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const OptionsRegex string = "^(([\\w\\.])+(\\.)([\\w]){2,4}([\\w]*))*$"

Variables

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

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

View Source
var TestParser = NewConfigManager()

TestParser acts as a test config manager that can be used globally.

Functions

func AddSource

func AddSource(s Source)

func Load

func Load()

Types

type ConfigManager

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

ConfigManager holds types for generic managers to generate configs.

func NewConfigManager

func NewConfigManager() *ConfigManager

NewConfigManager makes a configs manager.

func (*ConfigManager) AddSource

func (c *ConfigManager) AddSource(source Source)

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

func (*ConfigManager) Load

func (c *ConfigManager) Load()

Load handles configs func LoadValue directly.

func (*ConfigManager) Register

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

Register will add given configs to the general manager.

type EnvSource

type EnvSource struct{}

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 Options

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

func Register

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

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