Documentation ¶
Index ¶
- Constants
- func Bool(key string, defVal ...bool) bool
- func Data() map[string]Section
- func Delete(key string) bool
- func Error() error
- func Get(key string, defVal ...string) string
- func GetValue(key string) (string, bool)
- func HasKey(key string) bool
- func IgnoreCase(opts *Options)
- func Int(key string, defVal ...int) int
- func Int64(key string, defVal ...int64) int64
- func IsEmpty() bool
- func LoadData(data map[string]Section) error
- func LoadExists(files ...string) error
- func LoadFiles(files ...string) error
- func LoadStrings(strings ...string) error
- func MapStruct(key string, ptr interface{}) error
- func ParseEnv(opts *Options)
- func ParseEnvValue(val string) (newVal string)
- func ParseVar(opts *Options)
- func Readonly(opts *Options)
- func Reset()
- func SectionKeys(withDefaultSection bool) (ls []string)
- func Set(key string, val interface{}, section ...string) error
- func String(key string, defVal ...string) string
- func StringMap(name string) map[string]string
- func Strings(key string, sep ...string) []string
- func Uint(key string, defVal ...uint) uint
- func WithOptions(opts ...func(*Options))
- type Ini
- func (c *Ini) Bool(key string, defVal ...bool) (value bool)
- func (c *Ini) Data() map[string]Section
- func (c *Ini) DefSection() string
- func (c *Ini) DelSection(name string) (ok bool)
- func (c *Ini) Delete(key string) (ok bool)
- func (c *Ini) Error() error
- func (c *Ini) Get(key string, defVal ...string) string
- func (c *Ini) GetValue(key string) (val string, ok bool)
- func (c *Ini) HasKey(key string) (ok bool)
- func (c *Ini) HasSection(name string) bool
- func (c *Ini) Int(key string, defVal ...int) (value int)
- func (c *Ini) Int64(key string, defVal ...int64) (value int64)
- func (c *Ini) IsEmpty() bool
- func (c *Ini) LoadData(data map[string]Section) (err error)
- func (c *Ini) LoadExists(files ...string) (err error)
- func (c *Ini) LoadFiles(files ...string) (err error)
- func (c *Ini) LoadStrings(strings ...string) (err error)
- func (c *Ini) MapStruct(key string, ptr interface{}) error
- func (c *Ini) MapTo(ptr interface{}) error
- func (c *Ini) NewSection(name string, values map[string]string) (err error)
- func (c *Ini) Options() Options
- func (c *Ini) PrettyJSON() string
- func (c *Ini) Reset()
- func (c *Ini) Section(name string) Section
- func (c *Ini) SectionKeys(withDefaultSection bool) (ls []string)
- func (c *Ini) Set(key string, val interface{}, section ...string) (err error)
- func (c *Ini) SetSection(name string, values map[string]string) (err error)
- func (c *Ini) String(key string, defVal ...string) string
- func (c *Ini) StringMap(name string) (mp map[string]string)
- func (c *Ini) Strings(key string, sep ...string) (ss []string)
- func (c *Ini) Uint(key string, defVal ...uint) (value uint)
- func (c *Ini) WithOptions(opts ...func(*Options))
- func (c *Ini) WriteTo(out io.Writer) (n int64, err error)
- func (c *Ini) WriteToFile(file string) (int64, error)
- type Options
- type Section
Constants ¶
const ( SepSection = "." DefTagName = "ini" )
some default constants
Variables ¶
This section is empty.
Functions ¶
func Get ¶ added in v1.2.0
Get get a value by key string. you can use '.' split for get value in a special section
func GetValue ¶ added in v1.2.0
GetValue get a value by key string. you can use '.' split for get value in a special section
func IgnoreCase ¶ added in v1.2.0
func IgnoreCase(opts *Options)
IgnoreCase for get/set value by key
func LoadExists ¶ added in v1.2.0
LoadExists load files, will ignore not exists
func LoadStrings ¶ added in v1.2.0
LoadStrings load data from strings
func ParseEnv ¶ added in v1.2.0
func ParseEnv(opts *Options)
ParseEnv will parse ENV key on get value Usage:
ini.WithOptions(ini.ParseEnv)
func ParseEnvValue ¶ added in v1.2.0
ParseEnvValue parse ENV var value from input string
func ParseVar ¶ added in v1.2.0
func ParseVar(opts *Options)
ParseVar on get value Usage:
ini.WithOptions(ini.ParseVar)
func Readonly ¶ added in v1.2.0
func Readonly(opts *Options)
Readonly setting Usage: ini.NewWithOptions(ini.Readonly)
func SectionKeys ¶ added in v1.2.0
SectionKeys get all section names
func Set ¶ added in v1.2.0
Set a value to the section by key. if section is empty, will set to default section
func WithOptions ¶ added in v1.2.0
func WithOptions(opts ...func(*Options))
WithOptions apply some options
Types ¶
type Ini ¶ added in v1.2.0
type Ini struct {
// contains filtered or unexported fields
}
Ini config data manager
func NewWithOptions ¶ added in v1.2.0
NewWithOptions new a instance and with some options Usage: ini.NewWithOptions(ini.ParseEnv, ini.Readonly)
func (*Ini) Bool ¶ added in v1.2.0
Bool Looks up a value for a key in this section and attempts to parse that value as a boolean, along with a boolean result similar to a map lookup. of following(case insensitive):
- true
- false
- yes
- no
- off
- on
- 0
- 1
The `ok` boolean will be false in the event that the value could not be parsed as a bool
func (*Ini) DefSection ¶ added in v1.2.0
DefSection get default section name
func (*Ini) DelSection ¶ added in v1.2.0
DelSection del section by name
func (*Ini) Get ¶ added in v1.2.0
Get a value by key string. you can use '.' split for get value in a special section
func (*Ini) GetValue ¶ added in v1.2.0
GetValue a value by key string. you can use '.' split for get value in a special section
func (*Ini) HasSection ¶ added in v1.2.0
HasSection has section
func (*Ini) LoadExists ¶ added in v1.2.0
LoadExists load files, will ignore not exists
func (*Ini) LoadStrings ¶ added in v1.2.0
LoadStrings load data from strings
func (*Ini) MapStruct ¶ added in v1.2.0
MapStruct get config data and binding to the structure. Usage:
user := &Db{} ini.MapStruct("user", &user)
func (*Ini) NewSection ¶ added in v1.2.0
NewSection add new section data, existed will be replace
func (*Ini) Options ¶ added in v1.2.0
Options get options info. Notice: return is value. so, cannot change options
func (*Ini) PrettyJSON ¶ added in v1.2.0
PrettyJSON translate to pretty JSON string
func (*Ini) SectionKeys ¶ added in v1.2.0
SectionKeys get all section names
func (*Ini) Set ¶ added in v1.2.0
Set a value to the section by key. if section is empty, will set to default section
func (*Ini) SetSection ¶ added in v1.2.0
SetSection if not exist, add new section. If exist, will merge to old section.
func (*Ini) WithOptions ¶ added in v1.2.0
WithOptions apply some options
type Options ¶ added in v1.2.0
type Options struct { // Readonly set to read-only mode. default False Readonly bool // ParseEnv parse ENV var name. default True ParseEnv bool // ParseVar parse variable reference "%(varName)s". default False ParseVar bool // TagName for binding struct TagName string // VarOpen var left open char. default "%(" VarOpen string // VarClose var right close char. default ")s" VarClose string // IgnoreCase ignore key name case. default False IgnoreCase bool // DefSection default section name. default "__default", it's allow empty string. DefSection string // SectionSep sep char for split key path. default ".", use like "section.subKey" SectionSep string }
Options for config
func GetOptions ¶ added in v1.2.0
func GetOptions() Options
GetOptions get options info. Notice: return is value. so, cannot change Ini instance
Directories ¶
Path | Synopsis |
---|---|
Package parser is a Parser for parse INI format content to golang data There are example data: # comments name = inhere age = 28 debug = true hasQuota1 = 'this is val' hasQuota2 = "this is val1" shell = ${SHELL} noEnv = ${NotExist|defValue} ; array in def section tags[] = a tags[] = b tags[] = c ; comments [sec1] key = val0 some = value stuff = things ; array in section types[] = x types[] = y how to use, please see examples:
|
Package parser is a Parser for parse INI format content to golang data There are example data: # comments name = inhere age = 28 debug = true hasQuota1 = 'this is val' hasQuota2 = "this is val1" shell = ${SHELL} noEnv = ${NotExist|defValue} ; array in def section tags[] = a tags[] = b tags[] = c ; comments [sec1] key = val0 some = value stuff = things ; array in section types[] = x types[] = y how to use, please see examples: |