value

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package value provides the value types that req uses during evaluation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareType

func CompareType(a, b Value) error

CompareType compares the types of the given values.

func Truthy

func Truthy(v Value) bool

Truthy checks to see if the given value is a bool. If so, then the underlying bool is returned.

func Type

func Type(v Value) string

Type is a convenience function that returns the type of the given value.

Types

type Array

type Array struct {
	Items []Value
	// contains filtered or unexported fields
}

Array holds a list of values, and an underlying hash of each of the items in the array. This hash is used to perform in operations on the array.

func NewArray

func NewArray(items []Value) (*Array, error)

NewArray returns an array with the given list of values. A type check is performed on the array to ensure that they all contain the same type.

func (*Array) Get

func (a *Array) Get(v Value) (Value, error)

Get returns the value at the given index in the underlying array. If the given value cannot be used as an Int then an error is returned. If the index is out of bounds then the Zero value is returned.

func (*Array) Has

func (a *Array) Has(v Value) bool

Has returns whether or not the given value exists in the array.

func (*Array) MarshalJSON

func (a *Array) MarshalJSON() ([]byte, error)

func (*Array) Next

func (a *Array) Next() (Value, Value, error)

func (*Array) Set

func (a *Array) Set(_ bool, key, val Value) error

Set sets the value at the given key with the given value.

func (*Array) Sprint

func (a *Array) Sprint() string

Sprint is similar to String, the only difference being the Sprint method is called on each items in the array for formatting.

func (*Array) String

func (a *Array) String() string

String formats the array into a string. Each item in the array is space separated and wrapped in [ ]. The underlying items in the array will have the String method called on them for formatting.

type Bool

type Bool struct {
	Value bool
}

Bool is the value for boolean types.

func ToBool

func ToBool(v Value) (Bool, error)

ToBool attempts to type assert the given value to a bool.

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (Bool) Sprint

func (b Bool) Sprint() string

func (Bool) String

func (b Bool) String() string
type Cookie struct {
	*http.Cookie
}

func ToCookie added in v1.1.0

func ToCookie(v Value) (Cookie, error)

func (Cookie) Select added in v1.1.0

func (c Cookie) Select(val Value) (Value, error)

func (Cookie) Set added in v1.1.0

func (c Cookie) Set(name string, val Value) error

func (Cookie) Sprint added in v1.1.0

func (c Cookie) Sprint() string

func (Cookie) String added in v1.1.0

func (c Cookie) String() string

String formats the cookie to a string. The formatted string will detail the pointer at which the underlying response handle exists.

type Duration added in v1.1.0

type Duration struct {
	Value time.Duration
}

func ToDuration added in v1.1.0

func ToDuration(v Value) (Duration, error)

func (Duration) Sprint added in v1.1.0

func (d Duration) Sprint() string

func (Duration) String added in v1.1.0

func (d Duration) String() string

type File

type File struct {
	*os.File
}

File is the value for an open file. This holds the underlying handle to the file. The file value can be used as a stream.

func ToFile

func ToFile(v Value) (File, error)

ToFile attempts to type assert the given value to a file.

func (File) Close

func (f File) Close() error

func (File) Read

func (f File) Read(p []byte) (int, error)

func (File) Seek

func (f File) Seek(offset int64, whence int) (int64, error)

func (File) Sprint

func (f File) Sprint() string

Sprint returns the entire contents of the underlying file as a string. Once read, the file cursor is returned to the beginning of the file.

func (File) String

func (f File) String() string

String formats the file to a string. The formatted string will detail the pointer at which the underlying handle exists, along with the filename.

type Float

type Float struct {
	Value float64
}

func (Float) MarshalJSON

func (f Float) MarshalJSON() ([]byte, error)

func (Float) Sprint

func (f Float) Sprint() string

func (Float) String

func (f Float) String() string

type FormData

type FormData struct {
	ContentType string
	Data        *bytes.Reader
}

FormData is the value for data encoded as multipart/form-data. This holds the Content-Type of the data, which would be set in a request header, and the data itself.

func ToFormData

func ToFormData(v Value) (*FormData, error)

ToFormData attempts to type assert the given value to FormData.

func (*FormData) Select

func (f *FormData) Select(val Value) (Value, error)

Select will return the value of the field with the given name.

func (*FormData) Sprint

func (f *FormData) Sprint() string

Sprint returns the verbatim string representation of the FormData.

func (*FormData) String

func (f *FormData) String() string

String formats the FormData value to a string. The formatted string will contain the pointer at which FormData exists.

type Index

type Index interface {
	// Has checks to see if the given Value exists in the underlying index.
	Has(Value) bool

	Get(Value) (Value, error)

	Set(bool, Value, Value) error
}

Index represents a Value that can be indexed, such as an Object or an Array.

func ToIndex

func ToIndex(v Value) (Index, error)

ToIndex attempts to assert the given Value to an Index.

type Int

type Int struct {
	Value int64
}

Int is the value for int types.

func ToInt

func ToInt(v Value) (Int, error)

ToInt attempts to type assert the given value to an int.

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

func (Int) Sprint

func (i Int) Sprint() string

func (Int) String

func (i Int) String() string

type Iterable

type Iterable interface {
	// Next returns the key and value for the value being iterated over. The
	// error returned will be io.EOF when the end of the iterable has been
	// reached.
	Next() (Value, Value, error)
}

func ToIterable

func ToIterable(v Value) (Iterable, error)

ToIterable attempts to asset the given Value to an Iterable.

type Name

type Name struct {
	Value string
}

Name is the value for an identifier, such as a variable declaration or key.

func ToName

func ToName(v Value) (Name, error)

ToName attempts to type assert the given value to a name.

func (Name) Sprint

func (n Name) Sprint() string

func (Name) String

func (n Name) String() string

type Object

type Object struct {
	Order []string // The order in which the keys should be iterated.

	Pairs map[string]Value
	// contains filtered or unexported fields
}

Object holds a list of values indexed under a string.

func ToObject

func ToObject(v Value) (*Object, error)

ToObjectt attempts to type assert the given value to an object.

func (*Object) Get

func (o *Object) Get(v Value) (Value, error)

Get returns the value at the given index, if that value is a string. If there is no value at the given index, then Zero is returned.

func (*Object) Has

func (o *Object) Has(v Value) bool

Has checks to see if the current object has the current value, if that given value is a string.

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

func (*Object) Next

func (o *Object) Next() (Value, Value, error)

func (*Object) Set

func (o *Object) Set(strict bool, key, val Value) error

Set sets the value at the given key with the given value.

func (*Object) Sprint

func (o *Object) Sprint() string

Sprint is similar to String, the only difference being the Sprint method is called on each value in the object for formatting.

func (*Object) String

func (o *Object) String() string

String formats the object into a string. Each key-value pair is space spearated and wrapped in ( ). The underlying values in the array will have the String method called on them for formatting.

type Request

type Request struct {
	*http.Request

	Transport http.RoundTripper
}

Request is the value for an HTTP request. This holds the underlying handle to the request.

func ToRequest

func ToRequest(v Value) (*Request, error)

ToRequest attempts to type assert the given value to a request.

func (*Request) Select

func (r *Request) Select(val Value) (Value, error)

Select will return the value of the field with the given name.

func (*Request) Sprint

func (r *Request) Sprint() string

Sprint formats the request into a string. This makes a copy of the request body so as to not deplete the original.

func (*Request) String

func (r *Request) String() string

String formats the request to a string. The formatted string will detail the pointer at which the underlying request handle exists.

type Response

type Response struct {
	*http.Response
}

Response is the value for an HTTP response. This holds the underlying handle to the response.

func (Response) Select

func (r Response) Select(val Value) (Value, error)

Select will return the value of the field with the given name.

func (Response) Sprint

func (r Response) Sprint() string

Sprint formats the response into a string. This makes a copy of the response body so as to not deplete the original.

func (Response) String

func (r Response) String() string

String formats the response to a string. The formatted string will detail the pointer at which the underlying response handle exists.

type Selector

type Selector interface {
	Select(Value) (Value, error)
}

Selector represents a Value that has fields that can be accessed via a dot.

func ToSelector

func ToSelector(v Value) (Selector, error)

ToSelector attempts to assert the given Value to a Selector.

type Stream

type Stream interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}

Stream represents a stream of data that can be read. This would either be a Request/Response body or a File.

func BufferStream

func BufferStream(r *bytes.Reader) Stream

BufferStream returns a new stream for reading data from a location in memory.

func ToStream

func ToStream(v Value) (Stream, error)

ToStream attempts to assert the given Value to a Stream.

type String

type String struct {
	Value string
}

String is the value for string types.

func ToString

func ToString(v Value) (String, error)

ToString attempts to type assert the given value to a strinng.

func (String) MarshalJSON

func (s String) MarshalJSON() ([]byte, error)

func (String) Sprint

func (s String) Sprint() string

func (String) String

func (s String) String() string

type Time added in v1.1.0

type Time struct {
	Value time.Time
}

func (Time) Sprint added in v1.1.0

func (t Time) Sprint() string

func (Time) String added in v1.1.0

func (t Time) String() string

type Tuple added in v1.1.0

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

Tuple holds two different values that allows for the typle to be used as either value.

func (*Tuple) Sprint added in v1.1.0

func (t *Tuple) Sprint() string

func (*Tuple) String added in v1.1.0

func (t *Tuple) String() string

type Value

type Value interface {
	// String formats the Value into a string. The returned string is suitable
	// for display in a REPL. For example, strings are quoted.
	String() string

	// Sprint formats the Value into a string. This differs from String, in
	// that the returned string may not be suitable for display in a REPL.
	// For example, strings are not quoted, and the entire contents of Streams
	// are returned.
	Sprint() string
	// contains filtered or unexported methods
}

func Compare

func Compare(a Value, op syntax.Op, b Value) (Value, error)

Compare performs the given operation between the two values and returns the result of that comparison. This returned value will be a truthy value.

func DecodeJSON

func DecodeJSON(r io.Reader) (Value, error)

DecodeJSON attempts to decode all of the data in the given reader to JSON. The returned value will either be of type String, Int, Bool, Array, Object, or Zero depending on the JSON string being decoded.

func NewStream

func NewStream(s Stream) Value

NewStream turns the given stream into a value.

type Zero

type Zero struct{}

Zero is the value that represents a zero value. The zero value can be compared against any other type that also has an underlying zero value.

func (Zero) MarshalJSON

func (z Zero) MarshalJSON() ([]byte, error)

func (Zero) Sprint

func (z Zero) Sprint() string

func (Zero) String

func (z Zero) String() string

Jump to

Keyboard shortcuts

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