types

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2018 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilXError = NewXError(nil)

NilXError is the nil error value

View Source
var XBoolFalse = NewXBool(false)

XBoolFalse is the false boolean value

View Source
var XBoolTrue = NewXBool(true)

XBoolTrue is the true boolean value

View Source
var XDateZero = NewXDate(time.Time{})

XDateZero is the zero time value

View Source
var XNumberZero = NewXNumber(decimal.Zero)

XNumberZero is the zero number value

View Source
var XStringEmpty = NewXString("")

XStringEmpty is the empty string value

Functions

func Compare

func Compare(x1 XValue, x2 XValue) (int, error)

Compare returns the difference between two given values

func IsXError

func IsXError(x XValue) bool

IsXError returns whether the given value is an error value

func ToXBool

func ToXBool(x XValue) (XBool, XError)

ToXBool converts the given value to a boolean

func ToXDate

func ToXDate(env utils.Environment, x XValue) (XDate, XError)

ToXDate converts the given value to a time or returns an error if that isn't possible

func ToXJSON

func ToXJSON(x XValue) (XString, XError)

ToXJSON converts the given value to a JSON string

func ToXNumber

func ToXNumber(x XValue) (XNumber, XError)

ToXNumber converts the given value to a number or returns an error if that isn't possible

func ToXString

func ToXString(x XValue) (XString, XError)

ToXString converts the given value to a string

Types

type XArray

type XArray interface {
	XPrimitive
	XIndexable

	Append(XValue)
}

XArray is an array primitive in Excellent expressions

func NewXArray

func NewXArray(values ...XValue) XArray

NewXArray returns a new array with the given items

type XBool

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

XBool is a boolean true or false

func NewXBool

func NewXBool(value bool) XBool

NewXBool creates a new XBool

func (XBool) Compare

func (x XBool) Compare(other XBool) int

Compare compares this bool to another

func (XBool) MarshalJSON

func (x XBool) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XBool) Native

func (x XBool) Native() bool

Native returns the native value of this type

func (XBool) Reduce

func (x XBool) Reduce() XPrimitive

Reduce returns the primitive version of this type (i.e. itself)

func (*XBool) String

func (x *XBool) String() string

func (XBool) ToXBool

func (x XBool) ToXBool() XBool

ToXBool converts this type to a bool

func (XBool) ToXJSON

func (x XBool) ToXJSON() XString

ToXJSON is called when this type is passed to @(json(...))

func (XBool) ToXString

func (x XBool) ToXString() XString

ToXString converts this type to a string

func (*XBool) UnmarshalJSON

func (x *XBool) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XDate

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

XDate is a date

func NewXDate

func NewXDate(value time.Time) XDate

NewXDate creates a new date

func (XDate) Compare

func (x XDate) Compare(other XDate) int

Compare compares this date to another

func (XDate) MarshalJSON

func (x XDate) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XDate) Native

func (x XDate) Native() time.Time

Native returns the native value of this type

func (XDate) Reduce

func (x XDate) Reduce() XPrimitive

Reduce returns the primitive version of this type (i.e. itself)

func (*XDate) String

func (x *XDate) String() string

func (XDate) ToXBool

func (x XDate) ToXBool() XBool

ToXBool converts this type to a bool

func (XDate) ToXJSON

func (x XDate) ToXJSON() XString

ToXJSON is called when this type is passed to @(json(...))

func (XDate) ToXString

func (x XDate) ToXString() XString

ToXString converts this type to a string

func (*XDate) UnmarshalJSON

func (x *XDate) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XError

type XError interface {
	XPrimitive
	error
}

XError is an error

func NewXError

func NewXError(err error) XError

NewXError creates a new XError

func NewXErrorf

func NewXErrorf(format string, a ...interface{}) XError

NewXErrorf creates a new XError

func NewXResolveError

func NewXResolveError(resolvable XResolvable, key string) XError

NewXResolveError creates a new XError when a key can't be resolved on an XResolvable

func ToInteger

func ToInteger(x XValue) (int, XError)

ToInteger tries to convert the passed in value to an integer or returns an error if that isn't possible

type XIndexable

type XIndexable interface {
	XLengthable

	Index(index int) XValue
}

XIndexable is the interface for types which can be indexed into, e.g. foo.0. Such objects also need to be lengthable so that the engine knows what is a valid index and what isn't.

type XJSON

type XJSON []byte

XJSON is the base type for XJSONObject and XJSONArray

func (XJSON) MarshalJSON

func (x XJSON) MarshalJSON() ([]byte, error)

func (XJSON) Reduce

func (x XJSON) Reduce() XPrimitive

func (XJSON) String

func (x XJSON) String() string

String converts this type to native string

func (XJSON) ToXJSON

func (x XJSON) ToXJSON() XString

type XJSONArray

type XJSONArray struct {
	XJSON
}

func NewXJSONArray

func NewXJSONArray(data []byte) XJSONArray

func (XJSONArray) Index

func (x XJSONArray) Index(index int) XValue

func (XJSONArray) Length

func (x XJSONArray) Length() int

type XJSONObject

type XJSONObject struct {
	XJSON
}

func NewXJSONObject

func NewXJSONObject(data []byte) XJSONObject

func (XJSONObject) Length

func (x XJSONObject) Length() int

func (XJSONObject) Resolve

func (x XJSONObject) Resolve(key string) XValue

type XLengthable

type XLengthable interface {
	Length() int
}

XLengthable is the interface for types which have a length

type XMap

type XMap interface {
	XPrimitive
	XResolvable
	XLengthable

	Put(string, XValue)
	Keys() []string
}

XMap is a map primitive in Excellent expressions

func NewXEmptyMap

func NewXEmptyMap() XMap

NewXEmptyMap returns a new empty map

func NewXMap

func NewXMap(values map[string]XValue) XMap

NewXMap returns a new map with the given items

func ResolveKeys

func ResolveKeys(resolvable XResolvable, keys ...string) XMap

ResolveKeys is a utility function that resolves multiple keys on an XResolvable and returns the results as a map

type XNumber

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

XNumber is any whole or fractional number

func NewXNumber

func NewXNumber(value decimal.Decimal) XNumber

NewXNumber creates a new XNumber

func NewXNumberFromInt

func NewXNumberFromInt(value int) XNumber

NewXNumberFromInt creates a new XNumber from the given int

func NewXNumberFromInt64

func NewXNumberFromInt64(value int64) XNumber

NewXNumberFromInt64 creates a new XNumber from the given int

func RequireXNumberFromString

func RequireXNumberFromString(value string) XNumber

RequireXNumberFromString creates a new XNumber from the given string

func (XNumber) Compare

func (x XNumber) Compare(other XNumber) int

Compare compares this number to another

func (XNumber) Equals

func (x XNumber) Equals(other XNumber) bool

Equals determines equality for this type

func (XNumber) MarshalJSON

func (x XNumber) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XNumber) Native

func (x XNumber) Native() decimal.Decimal

Native returns the native value of this type

func (XNumber) Reduce

func (x XNumber) Reduce() XPrimitive

Reduce returns the primitive version of this type (i.e. itself)

func (*XNumber) String

func (x *XNumber) String() string

func (XNumber) ToXBool

func (x XNumber) ToXBool() XBool

ToXBool converts this type to a bool

func (XNumber) ToXJSON

func (x XNumber) ToXJSON() XString

ToXJSON is called when this type is passed to @(json(...))

func (XNumber) ToXString

func (x XNumber) ToXString() XString

ToXString converts this type to a string

func (*XNumber) UnmarshalJSON

func (x *XNumber) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XPrimitive

type XPrimitive interface {
	XValue

	ToXString() XString
	ToXBool() XBool
}

XPrimitive is the base interface of all Excellent primitive types

type XResolvable

type XResolvable interface {
	Resolve(key string) XValue
}

XResolvable is the interface for types which can be keyed into, e.g. foo.bar

type XString

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

XString is a string of characters

func MustMarshalToXString

func MustMarshalToXString(x interface{}) XString

MustMarshalToXString calls json.Marshal in the given value and panics in the case of an error

func NewXString

func NewXString(value string) XString

NewXString creates a new XString

func (XString) Compare

func (x XString) Compare(other XString) int

Compare compares this string to another

func (XString) Empty

func (x XString) Empty() bool

Empty returns whether this is an empty string

func (XString) Equals

func (x XString) Equals(other XString) bool

Equals determines equality for this type

func (XString) Length

func (x XString) Length() int

Length returns the length of this string

func (XString) MarshalJSON

func (x XString) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XString) Native

func (x XString) Native() string

Native returns the native value of this type

func (XString) Reduce

func (x XString) Reduce() XPrimitive

Reduce returns the primitive version of this type (i.e. itself)

func (XString) String

func (x XString) String() string

String converts this type to native string

func (XString) ToXBool

func (x XString) ToXBool() XBool

ToXBool converts this type to a bool

func (XString) ToXJSON

func (x XString) ToXJSON() XString

ToXJSON is called when this type is passed to @(json(...))

func (XString) ToXString

func (x XString) ToXString() XString

ToXString converts this type to a string

func (*XString) UnmarshalJSON

func (x *XString) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XValue

type XValue interface {
	ToXJSON() XString
	Reduce() XPrimitive
}

XValue is the base interface of all Excellent types

func JSONToXValue

func JSONToXValue(data []byte) XValue

Jump to

Keyboard shortcuts

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