Documentation
¶
Overview ¶
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:
Example (FullParse) ¶
p, err := Parse(iniStr, ModeFull)
// p, err := Parse(iniStr, ModeFull, NoDefSection)
if err != nil {
panic(err)
}
fmt.Printf("full parse:\n%#v\n", p.FullData())
Example (SimpleParse) ¶
// simple mode will ignore all array values
p, err := Parse(iniStr, ModeSimple)
if err != nil {
panic(err)
}
fmt.Printf("simple parse:\n%#v\n", p.SimpleData())
Index ¶
- Constants
- func Decode(blob []byte, v interface{}) error
- func Encode(v interface{}, defSection ...string) (out []byte, err error)
- func EncodeFull(data map[string]interface{}, defSection ...string) (out []byte, err error)
- func EncodeSimple(data map[string]map[string]string, defSection ...string) (out []byte, err error)
- func IgnoreCase(p *Parser)
- func NoDefSection(p *Parser)
- type Parser
- func (p *Parser) FullData() map[string]interface{}
- func (p *Parser) ParseBytes(bts []byte) (err error)
- func (p *Parser) ParseFrom(in *bufio.Scanner) (int64, error)
- func (p *Parser) ParseMode() uint8
- func (p *Parser) ParseString(str string) error
- func (p *Parser) ParsedData() interface{}
- func (p *Parser) Reset()
- func (p *Parser) SimpleData() map[string]map[string]string
- func (p *Parser) WithOptions(opts ...func(*Parser))
- type UserCollector
Examples ¶
Constants ¶
const ( ModeFull parseMode = 1 ModeSimple parseMode = 2 )
parse mode ModeFull - will parse array ModeSimple - don't parse array value
Variables ¶
This section is empty.
Functions ¶
func EncodeFull ¶ added in v1.0.4
EncodeFull full mode data to INI
func EncodeSimple ¶ added in v1.0.4
EncodeSimple data to INI
func NoDefSection ¶
func NoDefSection(p *Parser)
NoDefSection set don't return DefSection title Usage:
Parser.NewWithOptions(ini.ParseEnv)
Types ¶
type Parser ¶ added in v1.0.6
type Parser struct {
// -- options ---
// Ignore case for key name
IgnoreCase bool
// default section name. default is "__default"
DefSection string
// only for full parse mode
NoDefSection bool
// you can custom data collector
Collector UserCollector
// contains filtered or unexported fields
}
Parser definition
func FullParser ¶
FullParser create a full mode Parser with some options Deprecated: please use NewFulled() instead it.
func NewSimpled ¶ added in v1.1.0
NewSimpled create a simple mode Parser
func SimpleParser ¶
SimpleParser create a simple mode Parser. Deprecated: please use NewSimpled() instead it.
func (*Parser) ParseBytes ¶ added in v1.1.0
ParseBytes parse from bytes data
func (*Parser) ParseString ¶ added in v1.0.6
ParseString parse from string data
func (*Parser) ParsedData ¶ added in v1.0.6
func (p *Parser) ParsedData() interface{}
ParsedData get parsed data
func (*Parser) SimpleData ¶ added in v1.0.6
SimpleData get parsed data by simple parse
func (*Parser) WithOptions ¶ added in v1.0.6
WithOptions apply some options
type UserCollector ¶
UserCollector custom data collector. Notice: in simple mode, isSlice always is false.