conf

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 17 Imported by: 58

Documentation

Index

Constants

View Source
const (
	// KeyDelimiter is used as the default key delimiter in the default koanf instance.
	KeyDelimiter = "."
)

Variables

This section is empty.

Functions

func Abs

func Abs(path string) string

Abs 返回绝对路径

func AllSettings

func AllSettings() map[string]interface{}

func Bool

func Bool(path string) bool

func ConvertRefFileDSN

func ConvertRefFileDSN(base, dsn string) (*url.URL, error)

ConvertRefFileDSN if dsn use relative path,covert to abs path by a specified dir(use app run dir usually)

func Duration

func Duration(path string) time.Duration

func Float64

func Float64(path string) float64

func Get

func Get(path string) interface{}

func GetPathFromFileUrl

func GetPathFromFileUrl(fileUrl *url.URL) string

GetPathFromFileUrl get path of file dsn

func Int

func Int(path string) int

func IntSlice

func IntSlice(path string) []int

func IsSet

func IsSet(path string) bool

func Join

func Join(ps ...string) string

func String

func String(path string) string

func StringMap

func StringMap(path string) map[string]string

func StringSlice

func StringSlice(path string) []string

func Time

func Time(path string, layout string) time.Time

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 Global

func Global() *Configuration

Global return default(global) Configuration instance

func New

func New(opts ...Option) *Configuration

New create an application configuration instance

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) Duration

func (c *Configuration) Duration(path string) time.Duration

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) StringMap

func (c *Configuration) StringMap(path string) map[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) Time

func (c *Configuration) Time(path string, layout string) time.Time

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 BaseDir

func BaseDir(s string) Option

func IncludeFiles

func IncludeFiles(paths ...string) Option

IncludeFiles 附加文件中的配置将会重写主配置文件,对于非法的文件,将被忽略. you can set a configuration for dev ENV,but attach instance only effect in local file configuration

func IsGlobal

func IsGlobal(isGlobal bool) Option

func LocalPath

func LocalPath(s string) Option

LocalPath init local instance file path A s is file path

type Parser

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

Parser loads configuration.

func NewParser

func NewParser() *Parser

NewParser creates a new empty Parser instance.

func NewParserFromBuffer

func NewParserFromBuffer(buf io.Reader) (*Parser, error)

NewParserFromBuffer creates a new Parser by reading the given yaml buffer.

func NewParserFromFile

func NewParserFromFile(fileName string) (*Parser, error)

NewParserFromFile creates a new Parser by reading the given file.

func NewParserFromStringMap

func NewParserFromStringMap(data map[string]interface{}) *Parser

NewParserFromStringMap creates a parser from a map[string]interface{}.

func (*Parser) AllKeys

func (l *Parser) AllKeys() []string

AllKeys returns all keys holding a value, regardless of where they are set. Nested keys are returned with a KeyDelimiter separator.

func (*Parser) Get

func (l *Parser) Get(key string) interface{}

Get can retrieve any value given the key to use.

func (*Parser) IsSet

func (l *Parser) IsSet(key string) bool

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

func (l *Parser) MergeStringMap(cfg map[string]interface{}) error

MergeStringMap merges the configuration from the given map with the existing config. Note that the given map may be modified.

func (*Parser) Set

func (l *Parser) Set(key string, value interface{})

Set sets the value for the key.

func (*Parser) Sub

func (l *Parser) Sub(key string) (*Parser, error)

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

func (l Parser) ToBytes(p koanf.Parser) ([]byte, error)

ToBytes takes a Parser implementation and marshals the config map into bytes, for example, to TOML or JSON bytes.

func (*Parser) ToStringMap

func (l *Parser) ToStringMap() map[string]interface{}

ToStringMap creates a map[string]interface{} from a Parser.

func (*Parser) Unmarshal

func (l *Parser) Unmarshal(key string, rawVal interface{}) (err error)

Unmarshal unmarshals the config into a struct. Tags on the fields of the structure must be properly set.

func (*Parser) UnmarshalExact

func (l *Parser) UnmarshalExact(key string, intoCfg interface{}) (err error)

UnmarshalExact unmarshals the config into a struct, erroring if a field is nonexistent.

Jump to

Keyboard shortcuts

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