Documentation
¶
Overview ¶
Package cfg implements a simple config loader with hot reload feature. Local and remote file are both supported.
Index ¶
- Variables
- type Config
- type FsReader
- type Handler
- type Inifile
- type Option
- type Reader
- type Section
- func (s *Section) Keys() []string
- func (s *Section) Value(key string, defaultValue string) string
- func (s *Section) ValueBool(key string, defaultValue bool) bool
- func (s *Section) ValueFloat32(key string, defaultValue float32) float32
- func (s *Section) ValueFloat64(key string, defaultValue float64) float64
- func (s *Section) ValueInt(key string, defaultValue int) int
- func (s *Section) ValueInt32(key string, defaultValue int32) int32
- func (s *Section) ValueInt64(key string, defaultValue int64) int64
Constants ¶
This section is empty.
Variables ¶
var ReloadInterval = 30 * time.Second
ReloadInterval the frequency at configs are checked
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
sync.RWMutex
//Name name
Name string
//Content content
Content string
// contains filtered or unexported fields
}
Config Config represents an open config descriptor.
type FsReader ¶
type FsReader struct {
// contains filtered or unexported fields
}
FsReader FsReader implements `Reader` inferface for local file system
type Inifile ¶
type Inifile struct {
// contains filtered or unexported fields
}
Inifile represents all data from an INI file. see https://en.wikipedia.org/wiki/INI_file NOTE:
- Global properties will be ignored.
- Section and property names are not case sensitive. Both of them are converted to lower-case. And space is trimed in leading and trailing.
- The value of bool key is not case sensitive. "True" is same as "true". Space is trimed too.
type Reader ¶
type Reader interface {
//Read reads contents
Read(ctx context.Context) (string, error)
//ModTime get latest modification time
ModTime(ctx context.Context) (int64, error)
}
Reader Reader is the interface that wrap the Read and ModTime method of config
type Section ¶
type Section struct {
//Name the name of section
Name string
// contains filtered or unexported fields
}
Section information associated to a section in a INI File
func (*Section) ValueBool ¶
ValueBool get bool with key. return defaultValue if it doesn't exists or is invalid value. valid values: 0/1, on/off, true/false.
func (*Section) ValueFloat32 ¶
ValueFloat32 get float32 with key. return defaultValue if it doesn't exists or is invalid float32
func (*Section) ValueFloat64 ¶
ValueFloat64 get float64 with key. return defaultValue if it doesn't exists or is invalid float32
func (*Section) ValueInt ¶
ValueInt get int with key. return defaultValue if it doesn't exists or is invalid int
func (*Section) ValueInt32 ¶
ValueInt32 get int32 with key. return defaultValue if it doesn't exists or is invalid int64