Documentation ¶
Overview ¶
Package gparser provides convenient API for accessing/converting variable and JSON/XML/YAML/TOML.
Index ¶
- func VarToJson(value interface{}) ([]byte, error)
- func VarToJsonIndent(value interface{}) ([]byte, error)
- func VarToJsonIndentString(value interface{}) (string, error)
- func VarToJsonString(value interface{}) (string, 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()
- func (p *Parser) Export() string
- func (p *Parser) Get(pattern string, def ...interface{}) interface{}
- func (p *Parser) GetArray(pattern string, def ...interface{}) []interface{}
- func (p *Parser) GetBool(pattern string, def ...interface{}) bool
- func (p *Parser) GetDuration(pattern string, def ...interface{}) time.Duration
- func (p *Parser) GetFloat32(pattern string, def ...interface{}) float32
- func (p *Parser) GetFloat64(pattern string, def ...interface{}) float64
- func (p *Parser) GetFloats(pattern string, def ...interface{}) []float64
- func (p *Parser) GetGTime(pattern string, format ...string) *gtime.Time
- func (p *Parser) GetInt(pattern string, def ...interface{}) int
- func (p *Parser) GetInt16(pattern string, def ...interface{}) int16
- func (p *Parser) GetInt32(pattern string, def ...interface{}) int32
- func (p *Parser) GetInt64(pattern string, def ...interface{}) int64
- func (p *Parser) GetInt8(pattern string, def ...interface{}) int8
- func (p *Parser) GetInterfaces(pattern string, def ...interface{}) []interface{}
- func (p *Parser) GetInts(pattern string, def ...interface{}) []int
- func (p *Parser) GetMap(pattern string, def ...interface{}) map[string]interface{}
- func (p *Parser) GetString(pattern string, def ...interface{}) string
- func (p *Parser) GetStrings(pattern string, def ...interface{}) []string
- func (p *Parser) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (p *Parser) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (p *Parser) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (p *Parser) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (p *Parser) GetTime(pattern string, format ...string) time.Time
- func (p *Parser) GetToStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (p *Parser) GetToVar(pattern string, pointer interface{}) error
- func (p *Parser) GetUint(pattern string, def ...interface{}) uint
- func (p *Parser) GetUint16(pattern string, def ...interface{}) uint16
- func (p *Parser) GetUint32(pattern string, def ...interface{}) uint32
- func (p *Parser) GetUint64(pattern string, def ...interface{}) uint64
- func (p *Parser) GetUint8(pattern string, def ...interface{}) uint8
- func (p *Parser) GetVar(pattern string, def ...interface{}) *gvar.Var
- func (p *Parser) Len(pattern string) int
- func (p *Parser) MarshalJSON() ([]byte, error)
- 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) ToJsonIndentString() (string, error)
- func (p *Parser) ToJsonString() (string, error)
- func (p *Parser) ToMap() map[string]interface{}
- func (p *Parser) ToStruct(pointer interface{}) error
- func (p *Parser) ToStructDeep(pointer interface{}) error
- func (p *Parser) ToStructs(pointer interface{}) error
- func (p *Parser) ToStructsDeep(pointer 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)
- func (p *Parser) Value() interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VarToJsonIndent ¶
func VarToJsonIndentString ¶
func VarToJsonString ¶
func VarToStruct ¶
func VarToStruct(value interface{}, obj interface{}) error
func VarToXmlIndent ¶
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func Load ¶
Load loads content from specified file <path>, and creates a Parser object from its content.
func LoadContent ¶
LoadContent creates a Parser object from given content, it checks the data type of <content> automatically, supporting JSON, XML, YAML and TOML types of data.
func New ¶
New creates a Parser object with any variable type of <data>, but <data> should be a map or slice for data access reason, or it will make no sense. The <unsafe> param specifies whether using this Parser object in un-concurrent-safe context, which is false in default.
func NewUnsafe ¶
func NewUnsafe(value ...interface{}) *Parser
NewUnsafe creates a un-concurrent-safe Parser object.
func (*Parser) Append ¶
Append appends value to the value by specified <pattern>. The target value by <pattern> should be type of slice.
func (*Parser) Dump ¶
func (p *Parser) Dump()
Dump prints current Json object with more manually readable.
func (*Parser) Get ¶
Get returns value by specified <pattern>. It returns all values of current Json object, if <pattern> is empty or not specified. It returns nil if no value found by <pattern>.
We can also access slice item by its index number in <pattern>, eg: "items.name.first", "list.10".
It returns a default value specified by <def> if value for <pattern> is not found.
func (*Parser) GetArray ¶
GetArray gets the value by specified <pattern>, and converts it to a slice of []interface{}.
func (*Parser) GetBool ¶
GetBool gets the value by specified <pattern>, and converts it to bool. It returns false when value is: "", 0, false, off, nil; or returns true instead.
func (*Parser) GetDuration ¶
func (*Parser) GetFloat32 ¶
func (*Parser) GetFloat64 ¶
func (*Parser) GetInterfaces ¶
func (*Parser) GetMap ¶
GetMap gets the value by specified <pattern>, and converts it to map[string]interface{}.
func (*Parser) GetString ¶
GetString gets the value by specified <pattern>, and converts it to string.
func (*Parser) GetStrings ¶
GetStrings gets the value by specified <pattern>, and converts it to a slice of []string.
func (*Parser) GetStruct ¶
GetStruct gets the value by specified <pattern>, and converts it to specified object <pointer>. The <pointer> should be the pointer to an object.
func (*Parser) GetStructDeep ¶
func (p *Parser) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructDeep does GetStruct recursively.
func (*Parser) GetStructs ¶
func (p *Parser) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructs converts any slice to given struct slice.
func (*Parser) GetStructsDeep ¶
func (p *Parser) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructsDeep converts any slice to given struct slice recursively.
func (*Parser) GetToStruct ¶
func (p *Parser) GetToStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
GetToStruct is alias of GetStruct. Deprecated.
func (*Parser) GetToVar ¶
GetToVar gets the value by specified <pattern>, and converts it to specified golang variable <v>. The <v> should be a pointer type. Deprecated.
func (*Parser) Len ¶
Len returns the length/size of the value by specified <pattern>. The target value by <pattern> should be type of slice or map. It returns -1 if the target value is not found, or its type is invalid.
func (*Parser) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Parser) Remove ¶
Remove deletes value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.
func (*Parser) Set ¶
Set sets value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.
func (*Parser) SetSplitChar ¶
SetSplitChar sets the separator char for hierarchical data access.
func (*Parser) SetViolenceCheck ¶
SetViolenceCheck enables/disables violence check for hierarchical data access.
func (*Parser) ToArray ¶
func (p *Parser) ToArray() []interface{}
ToArray converts current object values to []interface{}. It returns nil if fails.
func (*Parser) ToJsonIndent ¶
func (*Parser) ToJsonIndentString ¶
func (*Parser) ToJsonString ¶
func (*Parser) ToMap ¶
ToMap converts current object values to map[string]interface{}. It returns nil if fails.
func (*Parser) ToStruct ¶
ToStruct converts current Json object to specified object. The <objPointer> should be a pointer type.