types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package types proviedes types that can be represented as Watson.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind is a type of Value.

const (
	Int    Kind = iota // 64-bit signed integer
	Uint               // 64-bit unsigned integer
	Float              // IEEE-754 64-bit floating-point number
	String             // string (represented as a byte array)
	Object             // object (set of key-value pairs)
	Array              // array
	Bool               // bool
	Nil                // nil
)

func (Kind) GoString

func (k Kind) GoString() string

type Marshaler

type Marshaler interface {
	MarshalWatson() (*Value, error)
}

By implementing Marshaler you can configure converting go objects into Values.

type TypeMismatch

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

TypeMismatch is an error that indicates that a given Value can't be converted into expected type.

func (*TypeMismatch) Error

func (e *TypeMismatch) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalWatson(*Value) error
}

By implementing Unmarshaler you can configure converting Values into go objects.

type Value

type Value struct {
	Kind   Kind
	Int    int64
	Uint   uint64
	Float  float64
	String []byte
	Object map[string]*Value
	Array  []*Value
	Bool   bool
}

Value is an arbitrary value that can be represented as Watson.

func NewArrayValue

func NewArrayValue(val []*Value) *Value

NewArrayValue creates a new value that contains an array.

func NewBoolValue

func NewBoolValue(val bool) *Value

NewBoolValue creates a new Value that contains a bool.

func NewFloatValue

func NewFloatValue(val float64) *Value

NewFloatValue creates a new Value that contains a floating point number.

func NewIntValue

func NewIntValue(val int64) *Value

NewIntValue creates a new Value that contains an integer.

func NewNilValue

func NewNilValue() *Value

NewNilValue creates a new Value that contains nil.

func NewObjectValue

func NewObjectValue(val map[string]*Value) *Value

NewObjectValue creates a new Value that contains an object.

func NewStringValue

func NewStringValue(val []byte) *Value

NewStringValue creates a new Value that contains a string.

func NewUintValue

func NewUintValue(val uint64) *Value

NewUintValue creates a new Value that contains an unsigned integer.

func ToValue

func ToValue(v interface{}) (*Value, error)

ToValue converts an arbitrary value into *Value.

See watson.Marshal for details.

func ToValueByReflection

func ToValueByReflection(v reflect.Value) (*Value, error)

`ToValueByReflection` does almost the same thing as `ToValue`, but it always uses reflection.

func (*Value) Bind

func (v *Value) Bind(to interface{}) error

Bind converts v into any go object and assigns it to `to`.

See watson.Marshal for more details.

func (*Value) BindByReflection

func (v *Value) BindByReflection(to reflect.Value) error

BindByReflection is almost the same as Bind but it always uses reflection.

func (*Value) DeepCopy

func (v *Value) DeepCopy() *Value

DeepCopy returns a deep copy of v.

func (*Value) GoString

func (v *Value) GoString() string

func (*Value) IsNaN

func (v *Value) IsNaN() bool

IsNaN returns true if v is a NaN; otherwise it returns false.

func (*Value) ToGoObject

func (val *Value) ToGoObject() interface{}

ToGoObject converts Value into one of the following type:

  • int64
  • uint64
  • float64
  • string
  • bool
  • (interface{})(nil)
  • []interface{} (the element of which is also one or many of these types)
  • map[string]interface{} (the value of which is also one or many of these types)

Jump to

Keyboard shortcuts

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