types

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 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 XBooleanFalse = NewXBoolean(false)

XBooleanFalse is the false boolean value

View Source
var XBooleanTrue = NewXBoolean(true)

XBooleanTrue is the true boolean value

View Source
var XDateTimeZero = NewXDateTime(time.Time{})

XDateTimeZero is the zero time value

View Source
var XNumberZero = NewXNumber(decimal.Zero)

XNumberZero is the zero number value

View Source
var XTextEmpty = NewXText("")

XTextEmpty is the empty text 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) (XBoolean, XError)

ToXBool converts the given value to a boolean

func ToXDate

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

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

func ToXJSON

func ToXJSON(x XValue) (XText, 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 ToXText added in v0.9.0

func ToXText(x XValue) (XText, XError)

ToXText 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 XBoolean added in v0.9.0

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

XBoolean is a boolean true or false

func NewXBoolean added in v0.9.0

func NewXBoolean(value bool) XBoolean

NewXBoolean creates a new boolean value

func (XBoolean) Compare added in v0.9.0

func (x XBoolean) Compare(other XBoolean) int

Compare compares this bool to another

func (XBoolean) MarshalJSON added in v0.9.0

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

MarshalJSON is called when a struct containing this type is marshaled

func (XBoolean) Native added in v0.9.0

func (x XBoolean) Native() bool

Native returns the native value of this type

func (XBoolean) Reduce added in v0.9.0

func (x XBoolean) Reduce() XPrimitive

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

func (*XBoolean) String added in v0.9.0

func (x *XBoolean) String() string

func (XBoolean) ToXBoolean added in v0.9.0

func (x XBoolean) ToXBoolean() XBoolean

ToXBoolean converts this type to a bool

func (XBoolean) ToXJSON added in v0.9.0

func (x XBoolean) ToXJSON() XText

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

func (XBoolean) ToXText added in v0.9.0

func (x XBoolean) ToXText() XText

ToXText converts this type to text

func (*XBoolean) UnmarshalJSON added in v0.9.0

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

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XDateTime added in v0.9.0

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

XDateTime is a datetime value

func NewXDateTime added in v0.9.0

func NewXDateTime(value time.Time) XDateTime

NewXDateTime creates a new date

func (XDateTime) Compare added in v0.9.0

func (x XDateTime) Compare(other XDateTime) int

Compare compares this date to another

func (XDateTime) MarshalJSON added in v0.9.0

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

MarshalJSON is called when a struct containing this type is marshaled

func (XDateTime) Native added in v0.9.0

func (x XDateTime) Native() time.Time

Native returns the native value of this type

func (XDateTime) Reduce added in v0.9.0

func (x XDateTime) Reduce() XPrimitive

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

func (*XDateTime) String added in v0.9.0

func (x *XDateTime) String() string

func (XDateTime) ToXBoolean added in v0.9.0

func (x XDateTime) ToXBoolean() XBoolean

ToXBoolean converts this type to a bool

func (XDateTime) ToXJSON added in v0.9.0

func (x XDateTime) ToXJSON() XText

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

func (XDateTime) ToXText added in v0.9.0

func (x XDateTime) ToXText() XText

ToXText converts this type to text

func (*XDateTime) UnmarshalJSON added in v0.9.0

func (x *XDateTime) 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() XText

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) ToXBoolean added in v0.9.0

func (x XNumber) ToXBoolean() XBoolean

ToXBoolean converts this type to a bool

func (XNumber) ToXJSON

func (x XNumber) ToXJSON() XText

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

func (XNumber) ToXText added in v0.9.0

func (x XNumber) ToXText() XText

ToXText converts this type to text

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

	ToXText() XText
	ToXBoolean() XBoolean
}

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 XText added in v0.9.0

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

XText is a simple tex value

func MustMarshalToXText added in v0.9.0

func MustMarshalToXText(x interface{}) XText

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

func NewXText added in v0.9.0

func NewXText(value string) XText

NewXText creates a new text value

func (XText) Compare added in v0.9.0

func (x XText) Compare(other XText) int

Compare compares this string to another

func (XText) Empty added in v0.9.0

func (x XText) Empty() bool

Empty returns whether this is an empty string

func (XText) Equals added in v0.9.0

func (x XText) Equals(other XText) bool

Equals determines equality for this type

func (XText) Length added in v0.9.0

func (x XText) Length() int

Length returns the length of this string

func (XText) MarshalJSON added in v0.9.0

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

MarshalJSON is called when a struct containing this type is marshaled

func (XText) Native added in v0.9.0

func (x XText) Native() string

Native returns the native value of this type

func (XText) Reduce added in v0.9.0

func (x XText) Reduce() XPrimitive

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

func (XText) String added in v0.9.0

func (x XText) String() string

String converts this type to native string

func (XText) ToXBoolean added in v0.9.0

func (x XText) ToXBoolean() XBoolean

ToXBoolean converts this type to a bool

func (XText) ToXJSON added in v0.9.0

func (x XText) ToXJSON() XText

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

func (XText) ToXText added in v0.9.0

func (x XText) ToXText() XText

ToXText converts this type to text

func (*XText) UnmarshalJSON added in v0.9.0

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

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XValue

type XValue interface {
	ToXJSON() XText
	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