Documentation
¶
Index ¶
- Constants
- func Abs(path string) string
- func AllSettings() map[string]interface{}
- func Bool(path string) bool
- func ConvertRefFileDSN(base, dsn string) (*url.URL, error)
- func Duration(path string) time.Duration
- func Float64(path string) float64
- func Get(path string) interface{}
- func GetPathFromFileUrl(fileUrl *url.URL) string
- func Int(path string) int
- func IntSlice(path string) []int
- func IsSet(path string) bool
- func Join(ps ...string) string
- func String(path string) string
- func StringMap(path string) map[string]string
- func StringSlice(path string) []string
- func Time(path string, layout string) time.Time
- type Configurable
- type Configuration
- func (c *Configuration) Abs(path string) string
- func (c *Configuration) AllSettings() map[string]interface{}
- func (c *Configuration) AppName() string
- func (c *Configuration) AsGlobal()
- func (c *Configuration) Bool(path string) bool
- func (c *Configuration) Copy() *Configuration
- func (c *Configuration) CutFromOperator(kf *koanf.Koanf) *Configuration
- func (c *Configuration) CutFromParser(p *Parser) *Configuration
- func (c *Configuration) Duration(path string) time.Duration
- func (c *Configuration) Float64(path string) float64
- func (c *Configuration) Get(key string) interface{}
- func (c *Configuration) GetBaseDir() string
- func (c *Configuration) Int(path string) int
- func (c *Configuration) IntSlice(path string) []int
- func (c *Configuration) IsSet(path string) bool
- func (c *Configuration) Load() *Configuration
- func (c *Configuration) Merge(b []byte) error
- func (c *Configuration) Parser() *Parser
- func (c *Configuration) ParserFromBytes(bs []byte) error
- func (c *Configuration) ParserOperator() *koanf.Koanf
- func (c *Configuration) Root() *Configuration
- func (c *Configuration) SetBaseDir(dir string)
- func (c *Configuration) String(path string) string
- func (c *Configuration) StringMap(path string) map[string]string
- func (c *Configuration) StringSlice(path string) []string
- func (c *Configuration) Sub(path string) *Configuration
- func (c *Configuration) SubOperator(path string) []*koanf.Koanf
- func (c *Configuration) Time(path string, layout string) time.Time
- func (c *Configuration) Version() string
- type Option
- type Parser
- func (l *Parser) AllKeys() []string
- func (l *Parser) Get(key string) interface{}
- func (l *Parser) IsSet(key string) bool
- func (l *Parser) MergeStringMap(cfg map[string]interface{}) error
- func (l *Parser) Set(key string, value interface{})
- func (l *Parser) Sub(key string) (*Parser, error)
- func (l Parser) ToBytes(p koanf.Parser) ([]byte, error)
- func (l *Parser) ToStringMap() map[string]interface{}
- func (l *Parser) Unmarshal(key string, rawVal interface{}) (err error)
- func (l *Parser) UnmarshalExact(key string, intoCfg interface{}) (err error)
Constants ¶
const (
// KeyDelimiter is used as the default key delimiter in the default koanf instance.
KeyDelimiter = "."
)
Variables ¶
This section is empty.
Functions ¶
func AllSettings ¶
func AllSettings() map[string]interface{}
func ConvertRefFileDSN ¶
ConvertRefFileDSN if dsn use relative path,covert to abs path by a specified dir(use app run dir usually)
func GetPathFromFileUrl ¶
GetPathFromFileUrl get path of file dsn
func StringSlice ¶
Types ¶
type Configurable ¶
type Configurable interface { // Apply set up property or field value by configuration // // cfg is the Configuration include the component; // path is the relative path to root,if root is the component,path will be empty // Apply also use for lazy load scene Apply(cfg *Configuration, path string) }
Configurable can initial by framework
type Configuration ¶
type Configuration struct { Development bool // contains filtered or unexported fields }
func NewFromBytes ¶
func NewFromBytes(b []byte, opts ...Option) *Configuration
NewFromBytes create from byte slice,return with a parser, But you'd better use Load()
func (*Configuration) Abs ¶
func (c *Configuration) Abs(path string) string
func (*Configuration) AllSettings ¶
func (c *Configuration) AllSettings() map[string]interface{}
func (*Configuration) AppName ¶
func (c *Configuration) AppName() string
AppName indicates the application's name
return the path 'appName' value, no set return empty
func (*Configuration) AsGlobal ¶
func (c *Configuration) AsGlobal()
func (*Configuration) Bool ¶
func (c *Configuration) Bool(path string) bool
func (*Configuration) Copy ¶
func (c *Configuration) Copy() *Configuration
func (*Configuration) CutFromOperator ¶
func (c *Configuration) CutFromOperator(kf *koanf.Koanf) *Configuration
func (*Configuration) CutFromParser ¶
func (c *Configuration) CutFromParser(p *Parser) *Configuration
func (*Configuration) Float64 ¶
func (c *Configuration) Float64(path string) float64
func (*Configuration) Get ¶
func (c *Configuration) Get(key string) interface{}
func (*Configuration) GetBaseDir ¶
func (c *Configuration) GetBaseDir() string
GetBaseDir return the application dir
func (*Configuration) Int ¶
func (c *Configuration) Int(path string) int
func (*Configuration) IntSlice ¶
func (c *Configuration) IntSlice(path string) []int
func (*Configuration) IsSet ¶
func (c *Configuration) IsSet(path string) bool
func (*Configuration) Load ¶
func (c *Configuration) Load() *Configuration
func (*Configuration) Merge ¶
func (c *Configuration) Merge(b []byte) error
Merge an input config stream,parameter b is YAML stream
func (*Configuration) Parser ¶
func (c *Configuration) Parser() *Parser
Parser return configuration operator
func (*Configuration) ParserFromBytes ¶
func (c *Configuration) ParserFromBytes(bs []byte) error
func (*Configuration) ParserOperator ¶
func (c *Configuration) ParserOperator() *koanf.Koanf
func (*Configuration) Root ¶
func (c *Configuration) Root() *Configuration
Root return root configuration if it came from Sub method
func (*Configuration) SetBaseDir ¶
func (c *Configuration) SetBaseDir(dir string)
SetBaseDir return the application dir
func (*Configuration) String ¶
func (c *Configuration) String(path string) string
func (*Configuration) StringSlice ¶
func (c *Configuration) StringSlice(path string) []string
func (*Configuration) Sub ¶
func (c *Configuration) Sub(path string) *Configuration
func (*Configuration) SubOperator ¶
func (c *Configuration) SubOperator(path string) []*koanf.Koanf
func (*Configuration) Version ¶
func (c *Configuration) Version() string
Version indicates the application's sem version
return the path 'version' value, no set return empty
type Option ¶
type Option func(*options)
Option the function to apply configuration option
func IncludeFiles ¶
IncludeFiles 附加文件中的配置将会重写主配置文件,对于非法的文件,将被忽略. you can set a configuration for dev ENV,but attach instance only effect in local file configuration
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser loads configuration.
func NewParserFromBuffer ¶
NewParserFromBuffer creates a new Parser by reading the given yaml buffer.
func NewParserFromFile ¶
NewParserFromFile creates a new Parser by reading the given file.
func NewParserFromStringMap ¶
NewParserFromStringMap creates a parser from a map[string]interface{}.
func (*Parser) AllKeys ¶
AllKeys returns all keys holding a value, regardless of where they are set. Nested keys are returned with a KeyDelimiter separator.
func (*Parser) IsSet ¶
IsSet checks to see if the key has been set in any of the data locations. IsSet is case-insensitive for a key.
func (*Parser) MergeStringMap ¶
MergeStringMap merges the configuration from the given map with the existing config. Note that the given map may be modified.
func (*Parser) Sub ¶
Sub returns new Parser instance representing a sub-config of this instance. It returns an error is the sub-config is not a map (use Get()) and an empty Parser if none exists.
func (Parser) ToBytes ¶
ToBytes takes a Parser implementation and marshals the config map into bytes, for example, to TOML or JSON bytes.
func (*Parser) ToStringMap ¶
ToStringMap creates a map[string]interface{} from a Parser.
func (*Parser) Unmarshal ¶
Unmarshal unmarshals the config into a struct. Tags on the fields of the structure must be properly set.
func (*Parser) UnmarshalExact ¶
UnmarshalExact unmarshals the config into a struct, erroring if a field is nonexistent.