config

package
v0.1.140 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config the config component

func New

func New(basePath, env string) *Config

func (*Config) AddParser

func (c *Config) AddParser(ext string, parser IConfigParser)

AddParser add parser for file with ext extension

func (*Config) AddPath

func (c *Config) AddPath(path string)

AddPath add path to end of search paths

func (*Config) CheckPath

func (c *Config) CheckPath() error

func (*Config) Get

func (c *Config) Get(key string, dftSplit ...string) interface{}

Get get value by dot separated key, the first part of key is file name without extension. if key is empty, all loaded config will be returned.

func (*Config) GetBool

func (c *Config) GetBool(key string, dft bool, dftSplit ...string) bool

GetBool get bool value from config, key is dot separated config key, dft is default value if key not exists.

func (*Config) GetFloat

func (c *Config) GetFloat(key string, dft float64, dftSplit ...string) float64

GetFloat get float value from config, key is dot separated config key, dft is default value if key not exists.

func (*Config) GetInt

func (c *Config) GetInt(key string, dft int, dftSplit ...string) int

GetInt get int value from config, key is dot separated config key, dft is default value if key not exists.

func (*Config) GetSliceBool

func (c *Config) GetSliceBool(key string, dftSplit ...string) []bool

GetSliceBool get []bool value from config, key is dot separated config key, nil is default value if key not exists.

func (*Config) GetSliceFloat

func (c *Config) GetSliceFloat(key string, dftSplit ...string) []float64

GetSliceFloat get []float value from config, key is dot separated config key, nil is default value if key not exists.

func (*Config) GetSliceInt

func (c *Config) GetSliceInt(key string, dftSplit ...string) []int

GetSliceInt get []int value from config, key is dot separated config key, nil is default value if key not exists.

func (*Config) GetSliceString

func (c *Config) GetSliceString(key string, dftSplit ...string) []string

GetSliceString get []string value from config, key is dot separated config key, nil is default value if key not exists.

func (*Config) GetString

func (c *Config) GetString(key string, dft string, dftSplit ...string) string

GetString get string value from config, key is dot separated config key, dft is default value if key not exists.

func (*Config) Init

func (c *Config) Init()

Initialize the

func (*Config) Set

func (c *Config) Set(key string, val interface{}, dftSplit ...string)

Set set value by dot separated key, if key is empty, the value will set to root, if val is nil, the key will be deleted.

type IConfig

type IConfig interface {
	AddParser(ext string, parser IConfigParser)
	AddPath(path string)
	GetBool(key string, dft bool, dftSplit ...string) bool
	GetInt(key string, dft int, dftSplit ...string) int
	GetFloat(key string, dft float64, dftSplit ...string) float64
	GetString(key string, dft string, dftSplit ...string) string
	GetSliceBool(key string, dftSplit ...string) []bool
	GetSliceInt(key string, dftSplit ...string) []int
	GetSliceFloat(key string, dftSplit ...string) []float64
	GetSliceString(key string, dftSplit ...string) []string
	Get(key string, dftSplit ...string) interface{}
	Set(key string, val interface{}, dftSplit ...string)
	CheckPath() error
}

type IConfigParser

type IConfigParser interface {
	Parse(path string) (map[string]interface{}, error)
}

type JsonParser

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

JsonParser parser for json config

func (*JsonParser) Parse

func (j *JsonParser) Parse(path string) (parseData map[string]interface{}, err error)

Parse parse json config, environment value like ${env||default} will expand

type YamlParser

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

YamlParser parser for yaml config

func (*YamlParser) Parse

func (y *YamlParser) Parse(path string) (parseData map[string]interface{}, err error)

Parse parse yaml config, environment value like ${env||default} will expand

func (*YamlParser) YamlDecode

func (y *YamlParser) YamlDecode(r io.Reader, out interface{}, strict ...bool) error

YamlDecode wrapper for yaml.Decoder, strict is for Decoder.SetStrict(). if type of out is map[string]interface{}, *map[string]interface{}, the inner map[interface{}]interface{} will fix to map[string]interface{} recursively. if type of out is *interface{}, the underlying type of out will change to *map[string]interface{}.

func (*YamlParser) YamlEncode

func (y *YamlParser) YamlEncode(w io.Writer, in interface{}) error

YamlEncode wrapper for yaml.Encoder.

func (*YamlParser) YamlMarshal

func (y *YamlParser) YamlMarshal(in interface{}) ([]byte, error)

YamlMarshal wrapper for yaml.Marshal.

func (*YamlParser) YamlUnmarshal

func (y *YamlParser) YamlUnmarshal(in []byte, out interface{}, strict ...bool) error

YamlUnmarshal wrapper for yaml.Unmarshal or yaml.UnmarshalStrict, if type of out is map[string]interface{}, *map[string]interface{}, the inner map[interface{}]interface{} will fix to map[string]interface{} recursively. if type of out is *interface{}, the underlying type of out will change to *map[string]interface{}.

Jump to

Keyboard shortcuts

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