parser

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2018 License: MIT Imports: 9 Imported by: 6

README

ini parser

This is a parser for parse INI format content to golang data

parser is ref the project: https://github.com/dombenson/go-ini, Thank you very much

Ref

License

MIT

Documentation

Overview

This 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

Examples

Constants

View Source
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 Decode

func Decode(blob []byte, v interface{}) (err error)

Decode

func Encode

func Encode(v interface{}, defSection ...string) (out []byte, err error)

Encode

func EncodeFull added in v1.0.4

func EncodeFull(data map[string]interface{}, defSection ...string) (out []byte, err error)

EncodeFull

func EncodeSimple added in v1.0.4

func EncodeSimple(data map[string]map[string]string, defSection ...string) (out []byte, err error)

EncodeSimple

func FullParser

func FullParser(opts ...func(*parser)) *parser

FullParser create a full mode parser

func IgnoreCase

func IgnoreCase(p *parser)

IgnoreCase set ignore-case

func NoDefSection

func NoDefSection(p *parser)

NoDefSection set don't return DefSection title usage: parser.NewWithOptions(ini.ParseEnv)

func Parse

func Parse(data string, mode parseMode, opts ...func(*parser)) (p *parser, err error)

Parse a INI data string to golang

func SimpleParser

func SimpleParser(opts ...func(*parser)) *parser

SimpleParser create a simple mode parser

Types

type UserCollector

type UserCollector func(section, key, val string, isArr bool)

UserCollector custom data collector. notice: in simple mode, isArr always is false.

Jump to

Keyboard shortcuts

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