anyvalue

package module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AVNil = &AnyValue{nil}

Functions

func Version

func Version() string

returns the current implementation version

Types

type AnyValue

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

func New

func New() *AnyValue

New returns a pointer to a new, empty `AnyValue` object

func NewFromInf

func NewFromInf(data interface{}) *AnyValue

New returns a pointer to a new, empty `AnyValue` object

func NewFromJson

func NewFromJson(body []byte) (*AnyValue, error)

NewFromJson returns a pointer to a new `AnyValue` object after unmarshaling `body` bytes

func NewFromJsonReader

func NewFromJsonReader(r io.Reader) (*AnyValue, error)

NewFromReader returns a *AnyValue by decoding from an io.Reader

func NewFromMsgPack

func NewFromMsgPack(body []byte) (*AnyValue, error)

NewFromMsgPack returns a pointer to a new `AnyValue` object after unmarshaling `body` bytes

func NewFromMsgPackReader

func NewFromMsgPackReader(r io.Reader) (*AnyValue, error)

NewFromReader returns a *AnyValue by decoding from an io.Reader

func NewFromYaml

func NewFromYaml(body []byte) (*AnyValue, error)

NewFromYaml returns a pointer to a new `AnyValue` object after unmarshaling `body` bytes

func NewFromYamlReader

func NewFromYamlReader(r io.Reader) (*AnyValue, error)

NewFromReader returns a *AnyValue by decoding from an io.Reader

func (*AnyValue) Array

func (j *AnyValue) Array() ([]interface{}, error)

Array type asserts to an `array`

func (*AnyValue) AsArray

func (j *AnyValue) AsArray(args ...[]interface{}) []interface{}

AsArray guarantees the return of a `[]interface{}` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, v := range js.Get("results").AsArray() {
	fmt.Println(i, v)
}

func (*AnyValue) AsBool

func (j *AnyValue) AsBool(args ...bool) bool

AsBool guarantees the return of a `bool` (with optional default)

useful when you explicitly want a `bool` in a single value return context:

myFunc(js.Get("param1").AsBool(), js.Get("optional_param").AsBool(true))

func (*AnyValue) AsFloat64

func (j *AnyValue) AsFloat64(args ...float64) float64

AsFloat64 guarantees the return of a `float64` (with optional default)

useful when you explicitly want a `float64` in a single value return context:

myFunc(js.Get("param1").AsFloat64(), js.Get("optional_param").AsFloat64(5.150))

func (*AnyValue) AsFloat64Arr

func (j *AnyValue) AsFloat64Arr(args ...[]float64) []float64

func (*AnyValue) AsInt

func (j *AnyValue) AsInt(args ...int) int

AsInt guarantees the return of an `int` (with optional default)

useful when you explicitly want an `int` in a single value return context:

myFunc(js.Get("param1").AsInt(), js.Get("optional_param").AsInt(5150))

func (*AnyValue) AsInt64

func (j *AnyValue) AsInt64(args ...int64) int64

AsInt64 guarantees the return of an `int64` (with optional default)

useful when you explicitly want an `int64` in a single value return context:

myFunc(js.Get("param1").AsInt64(), js.Get("optional_param").AsInt64(5150))

func (*AnyValue) AsInt64Arr

func (j *AnyValue) AsInt64Arr(args ...[]int64) []int64

func (*AnyValue) AsMap

func (j *AnyValue) AsMap(args ...map[string]interface{}) map[string]interface{}

AsMap guarantees the return of a `map[string]interface{}` (with optional default)

useful when you want to interate over map values in a succinct manner:

for k, v := range js.Get("dictionary").AsMap() {
	fmt.Println(k, v)
}

func (*AnyValue) AsStr

func (j *AnyValue) AsStr(args ...string) string

AsStr guarantees the return of a `string` (with optional default)

useful when you explicitly want a `string` in a single value return context:

myFunc(js.Get("param1").AsStr(), js.Get("optional_param").AsStr("Asmy_ault"))

func (*AnyValue) AsStrArr

func (j *AnyValue) AsStrArr(args ...[]string) []string

AsStrArr guarantees the return of a `[]string` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, s := range js.Get("results").AsStrArr() {
	fmt.Println(i, s)
}

func (*AnyValue) AsUInt64Arr

func (j *AnyValue) AsUInt64Arr(args ...[]uint64) []uint64

func (*AnyValue) AsUint64

func (j *AnyValue) AsUint64(args ...uint64) uint64

AsUInt64 guarantees the return of an `uint64` (with optional default)

useful when you explicitly want an `uint64` in a single value return context:

myFunc(js.Get("param1").AsUint64(), js.Get("optional_param").AsUint64(5150))

func (*AnyValue) Bool

func (j *AnyValue) Bool() (bool, error)

Bool type asserts to `bool`

func (*AnyValue) Bytes

func (j *AnyValue) Bytes() ([]byte, error)

Bytes type asserts to `[]byte`

func (*AnyValue) Del

func (j *AnyValue) Del(key string)

Del modifies `AnyValue` map by deleting `key` if it is present.

func (*AnyValue) EncodeJson

func (j *AnyValue) EncodeJson() ([]byte, error)

Encode returns its marshaled data as `[]byte`

func (*AnyValue) EncodeJsonPretty

func (j *AnyValue) EncodeJsonPretty() ([]byte, error)

EncodePretty returns its marshaled data as `[]byte` with indentation

func (*AnyValue) EncodeMsgPack

func (j *AnyValue) EncodeMsgPack() ([]byte, error)

Encode returns its marshaled data as `[]byte`

func (*AnyValue) EncodeYaml

func (j *AnyValue) EncodeYaml() ([]byte, error)

Encode returns its marshaled data as `[]byte`

func (*AnyValue) Exist

func (j *AnyValue) Exist(path string) (*AnyValue, bool)

CheckGet returns a pointer to a new `AnyValue` object and a `bool` identifying success or failure

useful for chained operations when success is important:

if data, ok := js.Get("top_level").Exist("inner"); ok {
    log.Println(data)
}

func (*AnyValue) Float64

func (j *AnyValue) Float64() (float64, error)

Float64 coerces into a float64

func (*AnyValue) Float64Arr

func (j *AnyValue) Float64Arr() ([]float64, error)

IntArr type asserts to an `array` of `int`

func (*AnyValue) Get

func (j *AnyValue) Get(path string) *AnyValue

GetValue searches for the item as specified by the branch without the need to deep dive using Get()'s.

js.GetValue("top_level.dict")

func (*AnyValue) GetIndex

func (j *AnyValue) GetIndex(index int) *AnyValue

GetIndex returns a pointer to a new `AnyValue` object for `index` in its `array` representation

this is the analog to Get when accessing elements of a json array instead of a json object:

js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()

func (*AnyValue) GetPath

func (j *AnyValue) GetPath(branch ...string) *AnyValue

GetPath searches for the item as specified by the branch without the need to deep dive using Get()'s.

js.GetPath("top_level", "dict")

func (*AnyValue) Has

func (j *AnyValue) Has(path string) bool

func (*AnyValue) Int

func (j *AnyValue) Int() (int, error)

Int coerces into an int

func (*AnyValue) Int64

func (j *AnyValue) Int64() (int64, error)

Int64 coerces into an int64

func (*AnyValue) Int64Arr

func (j *AnyValue) Int64Arr() ([]int64, error)

IntArr type asserts to an `array` of `int`

func (*AnyValue) Interface

func (j *AnyValue) Interface() interface{}

Interface returns the underlying data

func (*AnyValue) IsArray

func (j *AnyValue) IsArray() bool

func (*AnyValue) IsBool

func (j *AnyValue) IsBool() bool

func (*AnyValue) IsMap

func (j *AnyValue) IsMap() bool

func (*AnyValue) IsNumber

func (j *AnyValue) IsNumber() bool

func (*AnyValue) IsStr

func (j *AnyValue) IsStr() bool

func (*AnyValue) Map

func (j *AnyValue) Map() (map[string]interface{}, error)

Map type asserts to `map`

func (*AnyValue) MarshalJSON

func (j *AnyValue) MarshalJSON() ([]byte, error)

Implements the json.Marshaler interface.

func (*AnyValue) MarshalMsgPack

func (j *AnyValue) MarshalMsgPack() ([]byte, error)

Implements the msgpack.Marshaler interface.

func (*AnyValue) MarshalYAML

func (j *AnyValue) MarshalYAML() ([]byte, error)

Implements the yaml.Marshaler interface.

func (*AnyValue) Set

func (j *AnyValue) Set(path string, val interface{}) *AnyValue

func (*AnyValue) SetPath

func (j *AnyValue) SetPath(branch []string, val interface{}) *AnyValue

SetPath modifies `AnyValue`, recursively checking/creating map keys for the supplied path, and then finally writing in the value

func (*AnyValue) Str

func (j *AnyValue) Str() (string, error)

String type asserts to `string`

func (*AnyValue) StrArr

func (j *AnyValue) StrArr() ([]string, error)

StrArr type asserts to an `array` of `string`

func (*AnyValue) UInt64Arr

func (j *AnyValue) UInt64Arr() ([]uint64, error)

IntArr type asserts to an `array` of `int`

func (*AnyValue) Uint64

func (j *AnyValue) Uint64() (uint64, error)

Uint64 coerces into an uint64

func (*AnyValue) UnmarshalJSON

func (j *AnyValue) UnmarshalJSON(p []byte) error

Implements the json.Unmarshaler interface.

func (*AnyValue) UnmarshalMsgPack

func (j *AnyValue) UnmarshalMsgPack(p []byte) error

Implements the json.Unmarshaler interface.

func (*AnyValue) UnmarshalYAML

func (j *AnyValue) UnmarshalYAML(p []byte) error

Implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL