gf: github.com/gogf/gf/g/encoding/gparser Index | Files

package gparser

import "github.com/gogf/gf/g/encoding/gparser"

Package gparser provides convenient API for accessing/converting variable and JSON/XML/YAML/TOML.

Index

Package Files

gparser.go gparser_api.go gparser_api_config.go gparser_api_encoding.go gparser_api_new_load.go

func VarToJson Uses

func VarToJson(value interface{}) ([]byte, error)

func VarToJsonIndent Uses

func VarToJsonIndent(value interface{}) ([]byte, error)

func VarToJsonIndentString Uses

func VarToJsonIndentString(value interface{}) (string, error)

func VarToJsonString Uses

func VarToJsonString(value interface{}) (string, error)

func VarToStruct Uses

func VarToStruct(value interface{}, obj interface{}) error

func VarToToml Uses

func VarToToml(value interface{}) ([]byte, error)

func VarToXml Uses

func VarToXml(value interface{}, rootTag ...string) ([]byte, error)

func VarToXmlIndent Uses

func VarToXmlIndent(value interface{}, rootTag ...string) ([]byte, error)

func VarToYaml Uses

func VarToYaml(value interface{}) ([]byte, error)

type Parser Uses

type Parser struct {
    // contains filtered or unexported fields
}

func Load Uses

func Load(path string, unsafe ...bool) (*Parser, error)

Load loads content from specified file <path>, and creates a Parser object from its content.

func LoadContent Uses

func LoadContent(data interface{}, unsafe ...bool) (*Parser, error)

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 Uses

func New(value interface{}, unsafe ...bool) *Parser

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 Uses

func NewUnsafe(value ...interface{}) *Parser

NewUnsafe creates a un-concurrent-safe Parser object.

func (*Parser) Append Uses

func (p *Parser) Append(pattern string, value interface{}) error

Append appends value to the value by specified <pattern>. The target value by <pattern> should be type of slice.

func (*Parser) Dump Uses

func (p *Parser) Dump()

Dump prints current Json object with more manually readable.

func (*Parser) Export Uses

func (p *Parser) Export() string

func (*Parser) Get Uses

func (p *Parser) Get(pattern string, def ...interface{}) interface{}

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 Uses

func (p *Parser) GetArray(pattern string, def ...interface{}) []interface{}

GetArray gets the value by specified <pattern>, and converts it to a slice of []interface{}.

func (*Parser) GetBool Uses

func (p *Parser) GetBool(pattern string, def ...interface{}) bool

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 Uses

func (p *Parser) GetDuration(pattern string, def ...interface{}) time.Duration

func (*Parser) GetFloat32 Uses

func (p *Parser) GetFloat32(pattern string, def ...interface{}) float32

func (*Parser) GetFloat64 Uses

func (p *Parser) GetFloat64(pattern string, def ...interface{}) float64

func (*Parser) GetFloats Uses

func (p *Parser) GetFloats(pattern string, def ...interface{}) []float64

func (*Parser) GetGTime Uses

func (p *Parser) GetGTime(pattern string, format ...string) *gtime.Time

func (*Parser) GetInt Uses

func (p *Parser) GetInt(pattern string, def ...interface{}) int

func (*Parser) GetInt16 Uses

func (p *Parser) GetInt16(pattern string, def ...interface{}) int16

func (*Parser) GetInt32 Uses

func (p *Parser) GetInt32(pattern string, def ...interface{}) int32

func (*Parser) GetInt64 Uses

func (p *Parser) GetInt64(pattern string, def ...interface{}) int64

func (*Parser) GetInt8 Uses

func (p *Parser) GetInt8(pattern string, def ...interface{}) int8

func (*Parser) GetInterfaces Uses

func (p *Parser) GetInterfaces(pattern string, def ...interface{}) []interface{}

func (*Parser) GetInts Uses

func (p *Parser) GetInts(pattern string, def ...interface{}) []int

func (*Parser) GetMap Uses

func (p *Parser) GetMap(pattern string, def ...interface{}) map[string]interface{}

GetMap gets the value by specified <pattern>, and converts it to map[string]interface{}.

func (*Parser) GetString Uses

func (p *Parser) GetString(pattern string, def ...interface{}) string

GetString gets the value by specified <pattern>, and converts it to string.

func (*Parser) GetStrings Uses

func (p *Parser) GetStrings(pattern string, def ...interface{}) []string

GetStrings gets the value by specified <pattern>, and converts it to a slice of []string.

func (*Parser) GetStruct Uses

func (p *Parser) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error

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 Uses

func (p *Parser) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructDeep does GetStruct recursively.

func (*Parser) GetStructs Uses

func (p *Parser) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructs converts any slice to given struct slice.

func (*Parser) GetStructsDeep Uses

func (p *Parser) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructsDeep converts any slice to given struct slice recursively.

func (*Parser) GetTime Uses

func (p *Parser) GetTime(pattern string, format ...string) time.Time

func (*Parser) GetToStruct Uses

func (p *Parser) GetToStruct(pattern string, pointer interface{}, mapping ...map[string]string) error

GetToStruct is alias of GetStruct. Deprecated.

func (*Parser) GetToVar Uses

func (p *Parser) GetToVar(pattern string, pointer interface{}) error

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) GetUint Uses

func (p *Parser) GetUint(pattern string, def ...interface{}) uint

func (*Parser) GetUint16 Uses

func (p *Parser) GetUint16(pattern string, def ...interface{}) uint16

func (*Parser) GetUint32 Uses

func (p *Parser) GetUint32(pattern string, def ...interface{}) uint32

func (*Parser) GetUint64 Uses

func (p *Parser) GetUint64(pattern string, def ...interface{}) uint64

func (*Parser) GetUint8 Uses

func (p *Parser) GetUint8(pattern string, def ...interface{}) uint8

func (*Parser) GetVar Uses

func (p *Parser) GetVar(pattern string, def ...interface{}) *gvar.Var

GetVar returns a *gvar.Var with value by given <pattern>.

func (*Parser) Len Uses

func (p *Parser) Len(pattern string) int

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 Uses

func (p *Parser) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Parser) Remove Uses

func (p *Parser) Remove(pattern string) error

Remove deletes value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.

func (*Parser) Set Uses

func (p *Parser) Set(pattern string, value interface{}) error

Set sets value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.

func (*Parser) SetSplitChar Uses

func (p *Parser) SetSplitChar(char byte)

SetSplitChar sets the separator char for hierarchical data access.

func (*Parser) SetViolenceCheck Uses

func (p *Parser) SetViolenceCheck(check bool)

SetViolenceCheck enables/disables violence check for hierarchical data access.

func (*Parser) ToArray Uses

func (p *Parser) ToArray() []interface{}

ToArray converts current object values to []interface{}. It returns nil if fails.

func (*Parser) ToJson Uses

func (p *Parser) ToJson() ([]byte, error)

func (*Parser) ToJsonIndent Uses

func (p *Parser) ToJsonIndent() ([]byte, error)

func (*Parser) ToJsonIndentString Uses

func (p *Parser) ToJsonIndentString() (string, error)

func (*Parser) ToJsonString Uses

func (p *Parser) ToJsonString() (string, error)

func (*Parser) ToMap Uses

func (p *Parser) ToMap() map[string]interface{}

ToMap converts current object values to map[string]interface{}. It returns nil if fails.

func (*Parser) ToStruct Uses

func (p *Parser) ToStruct(pointer interface{}) error

ToStruct converts current Json object to specified object. The <objPointer> should be a pointer type.

func (*Parser) ToStructDeep Uses

func (p *Parser) ToStructDeep(pointer interface{}) error

func (*Parser) ToStructs Uses

func (p *Parser) ToStructs(pointer interface{}) error

func (*Parser) ToStructsDeep Uses

func (p *Parser) ToStructsDeep(pointer interface{}) error

func (*Parser) ToToml Uses

func (p *Parser) ToToml() ([]byte, error)

func (*Parser) ToXml Uses

func (p *Parser) ToXml(rootTag ...string) ([]byte, error)

func (*Parser) ToXmlIndent Uses

func (p *Parser) ToXmlIndent(rootTag ...string) ([]byte, error)

func (*Parser) ToYaml Uses

func (p *Parser) ToYaml() ([]byte, error)

func (*Parser) Value Uses

func (p *Parser) Value() interface{}

Val returns the value.

Package gparser imports 4 packages (graph) and is imported by 4 packages. Updated 2019-07-21. Refresh now. Tools for package owners.