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

func VarToJson Uses

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

func VarToJsonIndent Uses

func VarToJsonIndent(value interface{}) ([]byte, 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 []byte, 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() error

Dump prints current Json object with more manually readable.

func (*Parser) Get Uses

func (p *Parser) Get(pattern ...string) 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".

func (*Parser) GetArray Uses

func (p *Parser) GetArray(pattern string) []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) 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) GetFloat32 Uses

func (p *Parser) GetFloat32(pattern string) float32

func (*Parser) GetFloat64 Uses

func (p *Parser) GetFloat64(pattern string) float64

func (*Parser) GetFloats Uses

func (p *Parser) GetFloats(pattern string) []float64

func (*Parser) GetInt Uses

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

func (*Parser) GetInt16 Uses

func (p *Parser) GetInt16(pattern string) int16

func (*Parser) GetInt32 Uses

func (p *Parser) GetInt32(pattern string) int32

func (*Parser) GetInt64 Uses

func (p *Parser) GetInt64(pattern string) int64

func (*Parser) GetInt8 Uses

func (p *Parser) GetInt8(pattern string) int8

func (*Parser) GetInterfaces Uses

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

func (*Parser) GetInts Uses

func (p *Parser) GetInts(pattern string) []int

func (*Parser) GetMap Uses

func (p *Parser) GetMap(pattern string) 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) string

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

func (*Parser) GetStrings Uses

func (p *Parser) GetStrings(pattern string) []string

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

func (*Parser) GetTime Uses

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

func (*Parser) GetTimeDuration Uses

func (p *Parser) GetTimeDuration(pattern string) time.Duration

func (*Parser) GetToStruct Uses

func (p *Parser) GetToStruct(pattern string, objPointer interface{}) error

GetToStruct gets the value by specified <pattern>, and converts it to specified object <objPointer>. The <objPointer> should be the pointer to an object.

func (*Parser) GetToVar Uses

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

GetToVar gets the value by specified <pattern>, and converts it to specified golang variable <v>. The <v> should be a pointer type.

func (*Parser) GetUint Uses

func (p *Parser) GetUint(pattern string) uint

func (*Parser) GetUint16 Uses

func (p *Parser) GetUint16(pattern string) uint16

func (*Parser) GetUint32 Uses

func (p *Parser) GetUint32(pattern string) uint32

func (*Parser) GetUint64 Uses

func (p *Parser) GetUint64(pattern string) uint64

func (*Parser) GetUint8 Uses

func (p *Parser) GetUint8(pattern string) uint8

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) 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) 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(o interface{}) error

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

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)

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