Documentation ¶
Overview ¶
Package xini parse ini config files and utils.
Index ¶
- Constants
- Variables
- func FileLog(arr []ScannerLog) string
- func Marshal(v any) ([]byte, error)
- func ParseValue(v string) any
- 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, any)
- func (p *BaseParser) GetAllSection() []string
- func (p *BaseParser) GetDef(key string, def any) any
- func (p *BaseParser) HasKey(key string) bool
- func (p *BaseParser) IsValid() bool
- func (p *BaseParser) OpenFile(filename string) (error, []ScannerLog)
- 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 ...any) any
- func (p *BaseParser) Set(key string, value any) Parser
- func (p *BaseParser) SetFunc(key string, regFn func() any) Parser
- type BaseStrParse
- type Container
- func (c *Container) Del(key string) bool
- func (c *Container) Get(key string) (bool, any)
- func (c *Container) GetData() map[string]any
- func (c *Container) GetDef(key string, def any) any
- func (c *Container) HasKey(keys ...string) bool
- func (c *Container) Merge(data map[string]any) *Container
- func (c *Container) Reset() *Container
- func (c *Container) Set(key string, value any) *Container
- func (c *Container) SetFunc(key string, fn func() any) *Container
- func (c *Container) Value(params ...any) any
- type Encoder
- type FileParser
- type KvPairs
- type LnReader
- type Parser
- type RongParser
- type Scanner
- type ScannerLog
- 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{
"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": `^[^"'=]*['"\,]+$`,
"reg_str_symbol": `^["'].*["']+$`,
"reg_str_symbol_ln": `("[^"]*")|('[^']*')`,
"reg_i64_symbol": `^-{0,1}\d+$`,
"reg_f64_symbol": `^-{0,1}\d+(.\d+)+$`,
"reg_var_support": `^".*(\$|&)\w+.*"+$`,
"reg_var_support_val": `\$\w+`,
"reg_var_support_ref": `&\w+`,
"reg_include_smbl": `(?i)^include\s\w+`,
}
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{
`\,`: "_JC__COMMA",
`\{`: "_L__BRACE",
`\}`: "_R__BRACE",
`\=`: "_JC__EQUAL",
}
TranStrMap transfer character parsing
Functions ¶
func ParseValue ¶
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) GetAllSection ¶
func (p *BaseParser) GetAllSection() []string
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) (error, []ScannerLog)
OpenFile 打开并解析文件
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 ...any) any
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[any]any
func (*BaseStrParse) Line ¶
func (p *BaseStrParse) Line() int
func (*BaseStrParse) LoadContent ¶
func (p *BaseStrParse) LoadContent(content string) StrParser
type Container ¶
Container abstract data container
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder() *Encoder
type FileParser ¶
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, any) GetDef(key string, def any) any HasKey(key string) bool // SetFunc 函数式值获取 // 实现如动态值获取,类似 js 对象中的 [get function()] SetFunc(key string, regFn func() any) Parser // Raw 支持多级数据访问,获取元素数据 // 实际读取的原始数据为 map[string]string Raw(key string) string // Value get or set value: key, value(nil), default Value(params ...any) any GetAllSection() []string // Section the param format support // 1. fun Section(section, key string) 二级访问 // 2. fun Section(format string) 点操作 Section(params ...any) any GetData() map[string]any Set(key string, value any) Parser // 设置值 Del(key string) bool // 删除键值 IsValid() bool OpenFile(filename string) (error, []ScannerLog) 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 Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner File progressive scanner
func NewScanner ¶
func (*Scanner) Record ¶
func (c *Scanner) Record() []ScannerLog
type ScannerLog ¶
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