Documentation ¶
Overview ¶
Package gparser provides a flexible and easy way for accessing/converting variable and JSON/XML/YAML/TOML contents.
Index ¶
- func VarToJson(value interface{}) ([]byte, error)
- func VarToJsonIndent(value interface{}) ([]byte, error)
- func VarToStruct(value interface{}, obj interface{}) error
- func VarToToml(value interface{}) ([]byte, error)
- func VarToXml(value interface{}, rootTag ...string) ([]byte, error)
- func VarToXmlIndent(value interface{}, rootTag ...string) ([]byte, error)
- func VarToYaml(value interface{}) ([]byte, error)
- type Parser
- func (p *Parser) Append(pattern string, value interface{}) error
- func (p *Parser) Dump() error
- func (p *Parser) Get(pattern ...string) interface{}
- func (p *Parser) GetArray(pattern string) []interface{}
- func (p *Parser) GetBool(pattern string) bool
- func (p *Parser) GetFloat32(pattern string) float32
- func (p *Parser) GetFloat64(pattern string) float64
- func (p *Parser) GetFloats(pattern string) []float64
- func (p *Parser) GetInt(pattern string) int
- func (p *Parser) GetInt16(pattern string) int16
- func (p *Parser) GetInt32(pattern string) int32
- func (p *Parser) GetInt64(pattern string) int64
- func (p *Parser) GetInt8(pattern string) int8
- func (p *Parser) GetInterfaces(pattern string) []interface{}
- func (p *Parser) GetInts(pattern string) []int
- func (p *Parser) GetMap(pattern string) map[string]interface{}
- func (p *Parser) GetString(pattern string) string
- func (p *Parser) GetStrings(pattern string) []string
- func (p *Parser) GetTime(pattern string, format ...string) time.Time
- func (p *Parser) GetTimeDuration(pattern string) time.Duration
- func (p *Parser) GetToStruct(pattern string, objPointer interface{}) error
- func (p *Parser) GetToVar(pattern string, v interface{}) error
- func (p *Parser) GetUint(pattern string) uint
- func (p *Parser) GetUint16(pattern string) uint16
- func (p *Parser) GetUint32(pattern string) uint32
- func (p *Parser) GetUint64(pattern string) uint64
- func (p *Parser) GetUint8(pattern string) uint8
- func (p *Parser) Len(pattern string) int
- func (p *Parser) Remove(pattern string) error
- func (p *Parser) Set(pattern string, value interface{}) error
- func (p *Parser) SetSplitChar(char byte)
- func (p *Parser) SetViolenceCheck(check bool)
- func (p *Parser) ToArray() []interface{}
- func (p *Parser) ToJson() ([]byte, error)
- func (p *Parser) ToJsonIndent() ([]byte, error)
- func (p *Parser) ToMap() map[string]interface{}
- func (p *Parser) ToStruct(o interface{}) error
- func (p *Parser) ToToml() ([]byte, error)
- func (p *Parser) ToXml(rootTag ...string) ([]byte, error)
- func (p *Parser) ToXmlIndent(rootTag ...string) ([]byte, error)
- func (p *Parser) ToYaml() ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VarToJsonIndent ¶
func VarToStruct ¶
func VarToStruct(value interface{}, obj interface{}) error
将变量解析为对应的struct对象,注意传递的参数为struct对象指针
func VarToXmlIndent ¶
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func LoadContent ¶
支持的数据内容格式:json(默认), xml, yaml/yml, toml
func (*Parser) Get ¶
根据约定字符串方式访问json解析数据,参数形如: "items.name.first", "list.0"; 当pattern为空时,表示获取所有数据 返回的结果类型的interface{},因此需要自己做类型转换; 如果找不到对应节点的数据,返回nil;
func (*Parser) GetFloat32 ¶
func (*Parser) GetFloat64 ¶
func (*Parser) GetInterfaces ¶
func (*Parser) GetStrings ¶
func (*Parser) GetTimeDuration ¶ added in v1.5.0
func (*Parser) GetToStruct ¶
将指定变量转换为struct对象(对象属性赋值)
func (*Parser) SetViolenceCheck ¶
设置是否执行层级冲突检查,当键名中存在层级符号时需要开启该特性,默认为关闭。 开启比较耗性能,也不建议允许键名中存在分隔符,最好在应用端避免这种情况。
func (*Parser) ToJsonIndent ¶
Click to show internal directories.
Click to hide internal directories.