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
- Variables
- func Decode(blob []byte, ptr interface{}) error
- func Encode(v interface{}) ([]byte, 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 EncodeWithDefName(v interface{}, 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) LiteSection(name string) map[string]string
- func (p *Parser) MapStruct(ptr interface{}) (err error)
- 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)) *Parser
- type UserCollector
Examples ¶
Constants ¶
const ( MultiLineValMarkS = "'''" MultiLineValMarkD = `"""` )
special chars consts
const ( TokMLValMarkS = 'm' // multi line value by single quotes: ”' TokMLValMarkD = 'M' // multi line value by double quotes: """ )
token consts
const ( ModeFull parseMode = 1 ModeLite parseMode = 2 ModeSimple parseMode = 2 )
mode of parse data
ModeFull - will parse inline array ModeLite/ModeSimple - don't parse array value
const DefSection = "__default"
DefSection default section key name
Variables ¶
var TagName = "ini"
TagName default tag-name of mapping data to struct
Functions ¶
func EncodeFull ¶
EncodeFull full mode data to INI, can set default section name
func EncodeSimple ¶
EncodeSimple data to INI
func EncodeWithDefName ¶ added in v2.1.2
EncodeWithDefName golang data(map, struct) to INI, can set default section name
func NoDefSection ¶
func NoDefSection(p *Parser)
NoDefSection set don't return DefSection title
Usage:
Parser.NewFulled(ini.ParseEnv)
Types ¶
type Parser ¶
type Parser struct {
// TagName of mapping data to struct
TagName string
// 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 NewSimpled ¶
NewSimpled create a simple mode Parser
func (*Parser) LiteSection ¶ added in v2.1.2
LiteSection get parsed data by simple parse
func (*Parser) ParseBytes ¶
ParseBytes parse from bytes data
func (*Parser) ParseString ¶
ParseString parse from string data
func (*Parser) SimpleData ¶
SimpleData get parsed data by simple parse
func (*Parser) WithOptions ¶
WithOptions apply some options
type UserCollector ¶
UserCollector custom data collector.
Notice: in simple mode, isSlice always is false.