Documentation ¶
Overview ¶
Package xini parse ini config files and utils.
Index ¶
- Constants
- Variables
- func ParseValue(v string) interface{}
- func StrClear(s string) string
- type BaseParser
- func (p *BaseParser) Del(key string) bool
- func (p BaseParser) Driver() string
- func (p *BaseParser) ErrorMsg() string
- func (p *BaseParser) Get(key string) (bool, interface{})
- func (p *BaseParser) GetAllSection() []string
- func (p *BaseParser) GetDef(key string, def interface{}) interface{}
- func (p *BaseParser) HasKey(key string) bool
- func (p *BaseParser) IsValid() bool
- func (p *BaseParser) OpenFile(filename string) Parser
- func (p *BaseParser) Raw(key string) string
- func (p *BaseParser) ReadStr(content string) Parser
- func (p *BaseParser) Save() bool
- func (p *BaseParser) SaveAsFile(filename string) bool
- func (p *BaseParser) Section(params ...interface{}) interface{}
- func (p *BaseParser) Set(key string, value interface{}) Parser
- func (p *BaseParser) SetFunc(key string, regFn func() interface{}) Parser
- type BaseStrParse
- type Container
- func (c *Container) Del(key interface{}) bool
- func (c *Container) Get(key interface{}) (bool, interface{})
- func (c *Container) GetData() map[interface{}]interface{}
- func (c *Container) GetDef(key interface{}, def interface{}) interface{}
- func (c *Container) HasKey(keys ...interface{}) bool
- func (c *Container) Merge(data map[interface{}]interface{}) *Container
- func (c *Container) Reset() *Container
- func (c *Container) Set(key, value interface{}) *Container
- func (c *Container) SetFunc(key string, fn func() interface{}) *Container
- func (c *Container) Value(params ...interface{}) interface{}
- type FileParser
- type LnReader
- type Parser
- type RongParser
- type StrParser
- type TomlParser
Constants ¶
const ( SupportNameIni = "ini" SupportNameRong = "rong" SupportNameToml = "toml" )
const ( Author = "Joshua Conero" // author 作者 Name = "conero/ini" Version = "2.1.0-alpha.4" // version 版本号 Release = "20190617" // build 发布日期 Description = "ini parser for golang" // name 名称 Since = "20171028" // start 开始时间 Copyright = "@Conero" // copyright 版权 )
Variables ¶
var IniParseSettings map[string]string = map[string]string{
"equal": "=",
"comment": "#|;",
"mcomment1": "'''",
"mcomment2": "'''",
"limiter": ",",
"scope1": "{",
"scope2": "}",
"reg_comment": "^[#;]",
"reg_section": "^\\[[^\\[^\\]}]*\\]$",
"reg_section_sg": "(\\[)|(\\])",
"reg_scope": "\\{[^\\{^\\}]*\\}",
"reg_scope_sg": "^\\{.*\\}$",
"mlstring": `"|'`,
"reg_clear_mls": `"|'`,
"reg_has_comment": `#|;`,
"reg_is_mlstring": `^[\w]+[=\s]+("|'){1}[^"']*$`,
"reg_is_mlstring_nk": `^["']{1}[^"'\,]+$`,
"reg_mlstring_sta": `^['"].*`,
"reg_mlstring_end": `^[^"'=]*['"\,]+$`,
}
IniParseSettings ini-parse set base
var TranCommentMap map[string]string = map[string]string{
`\;`: "_JC__COMMIT1",
`\#`: "_JC__COMMIT2",
}
TranCommentMap comment character parsing
var TranStrMap map[string]string = map[string]string{
`\,`: "_JC__COMMA",
`\{`: "_L__BRACE",
`\}`: "_R__BRACE",
`\=`: "_JC__EQUAL",
}
TranStrMap transfer character parsing
Functions ¶
func ParseValue ¶
func ParseValue(v string) interface{}
ParseValue parse the data value, the format like
bool: true/false/TRUE/FALSE string: '字符串', "字符串" 以及无法解析的参数 int64: 47, 52, -49552 float64: 3.14, -0.24552 null: nil 空值时,默认为 nil
Types ¶
type BaseParser ¶
type BaseParser struct { Container // contains filtered or unexported fields }
BaseParser base and default file parse, support the standard ini configure file
func (*BaseParser) Del ¶
func (p *BaseParser) Del(key string) bool
func (BaseParser) Driver ¶
func (p BaseParser) Driver() string
Driver the current reader driver type
func (*BaseParser) ErrorMsg ¶
func (p *BaseParser) ErrorMsg() string
ErrorMsg get the last error message
func (*BaseParser) Get ¶
func (p *BaseParser) Get(key string) (bool, interface{})
func (*BaseParser) GetAllSection ¶
func (p *BaseParser) GetAllSection() []string
func (*BaseParser) GetDef ¶
func (p *BaseParser) GetDef(key string, def interface{}) interface{}
func (*BaseParser) HasKey ¶
func (p *BaseParser) HasKey(key string) bool
func (*BaseParser) IsValid ¶
func (p *BaseParser) IsValid() bool
func (*BaseParser) OpenFile ¶
func (p *BaseParser) OpenFile(filename string) Parser
func (*BaseParser) Raw ¶
func (p *BaseParser) Raw(key string) string
Raw get the raw value that not parse to what the data by itself
func (*BaseParser) ReadStr ¶
func (p *BaseParser) ReadStr(content string) Parser
func (*BaseParser) Save ¶
func (p *BaseParser) Save() bool
func (*BaseParser) SaveAsFile ¶
func (p *BaseParser) SaveAsFile(filename string) bool
func (*BaseParser) Section ¶
func (p *BaseParser) Section(params ...interface{}) interface{}
func (*BaseParser) Set ¶
func (p *BaseParser) Set(key string, value interface{}) Parser
func (*BaseParser) SetFunc ¶
func (p *BaseParser) SetFunc(key string, regFn func() interface{}) Parser
type BaseStrParse ¶
type BaseStrParse struct {
// contains filtered or unexported fields
}
BaseStrParse base string to parse using ini syntax
func (*BaseStrParse) GetData ¶
func (p *BaseStrParse) GetData() map[interface{}]interface{}
func (*BaseStrParse) Line ¶
func (p *BaseStrParse) Line() int
func (*BaseStrParse) LoadContent ¶
func (p *BaseStrParse) LoadContent(content string) StrParser
type Container ¶
type Container struct { Data map[interface{}]interface{} // contains filtered or unexported fields }
Container abstract data container
func (*Container) GetData ¶
func (c *Container) GetData() map[interface{}]interface{}
GetData the data of `Container`
func (*Container) GetDef ¶
func (c *Container) GetDef(key interface{}, def interface{}) interface{}
GetDef get value by key with default.
func (*Container) Value ¶
func (c *Container) Value(params ...interface{}) interface{}
Value the container get or set value Container.Value(key interface{}) get data value Container.Value(key, value interface{}) set data value Container.Value(key, nil, def interface{}) get data value with default c.GetDef(key, def interface{})
type FileParser ¶
type FileParser interface { Line() int // 获取总行数 GetData() map[interface{}]interface{} }
FileParser File parser
type LnReader ¶
type LnReader struct { Filename string // 文件名 // contains filtered or unexported fields }
LnReader the lines of file reader
type Parser ¶
type Parser interface { Get(key string) (bool, interface{}) GetDef(key string, def interface{}) interface{} HasKey(key string) bool // SetFunc 函数式值获取 // 实现如动态值获取,类似 js 对象中的 [get function()] SetFunc(key string, regFn func() interface{}) Parser // Raw 支持多级数据访问,获取元素数据 // 实际读取的原始数据为 map[string]string Raw(key string) string // Value get or set value: key, value(nil), default Value(params ...interface{}) interface{} GetAllSection() []string // Section the param format support // 1. fun Section(section, key string) 二级访问 // 2. fun Section(format string) 点操作 Section(params ...interface{}) interface{} GetData() map[interface{}]interface{} Set(key string, value interface{}) Parser // 设置值 Del(key string) bool // 删除键值 IsValid() bool OpenFile(filename string) Parser ReadStr(content string) Parser ErrorMsg() string // 错误信息 Save() bool SaveAsFile(filename string) bool Driver() string }
Parser the ini file base parse interface
type RongParser ¶
type RongParser struct {
BaseParser
}
RongParser the Rong Parser inherited from BaseParser
func (RongParser) Driver ¶
func (p RongParser) Driver() string
type StrParser ¶
type StrParser interface { Line() int GetData() map[interface{}]interface{} LoadContent(content string) StrParser }
StrParser the string parse
type TomlParser ¶
type TomlParser struct {
BaseParser
}
TomlParser Toml file syntax parse @todo need todo
func (TomlParser) Driver ¶
func (p TomlParser) Driver() string
func (*TomlParser) MoreToDo ¶
func (p *TomlParser) MoreToDo() string