property

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

README

Hannibal / unit

This package wraps a number of common data values with conversions used in ActivityStreams. This is important because JSON-LD allows any piece of data to be represented in multiple formats. This wrapper allows safe access to indidividual values even when there are nil values slices, or maps of values present.

Usage

value := property.NewValue("http://foo.com")

foo.Raw() // returns "foo"

// Traverse Arrays
foo.Len() // returns 1
foo.Head().Raw() // returns "http://foo.com"
foo.Tail().Raw() // returns a nil value

// Represent maps
foo.Map() // returns a map with "id"="http://foo.com"
foo.Set("name", "Foo") // converts foo to a map and sets a new property
foo.Get("name").Raw() // returns "Foo"

Interfaces

Everything implements the property.Value interface, which provides several low-level manipulations for reading, writing, and transforming values. You can implement this interface in other packages to use other custom types with the rest of the hannibal library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBool

func IsBool(value any) bool

IsBool returns TRUE if the value represents a bool

func IsFloat

func IsFloat(value any) bool

IsInt returns TRUE if the value represents a float

func IsInt

func IsInt(value any) bool

IsInt returns TRUE if the value represents an int

func IsInt64

func IsInt64(value any) bool

IsInt64 returns TRUE if the value represents an int64

func IsMap

func IsMap(value any) bool

IsMap returns TRUE if the value represents a map

func IsSlice

func IsSlice(value any) bool

IsSlice returns TRUE if the value represents a slice

func IsString

func IsString(value any) bool

IsString returns TRUE if the value represents a string

func IsTime

func IsTime(value any) bool

IsTime returns TRUE if the value represents a time.Time

Types

type Bool

type Bool bool

func (Bool) Bool

func (value Bool) Bool() bool

func (Bool) Clone

func (value Bool) Clone() Value

func (Bool) Get

func (value Bool) Get(_ string) Value

Get returns a value of the given property

func (Bool) Head

func (value Bool) Head() Value

Head returns the first value in a slice

func (Bool) IsBool

func (value Bool) IsBool() bool

func (Bool) IsNil

func (value Bool) IsNil() bool

func (Bool) Len

func (value Bool) Len() int

Len returns the number of elements in the value

func (Bool) Map

func (value Bool) Map() map[string]any

func (Bool) Raw

func (value Bool) Raw() any

func (Bool) Set

func (value Bool) Set(property string, propertyValue any) Value

Set returns the value with the given property set

func (Bool) String

func (value Bool) String() string

func (Bool) Tail

func (value Bool) Tail() Value

Tail returns all values in a slice except the first

type BoolGetter

type BoolGetter interface {
	// Bool returns a value typed as a bool
	Bool() bool
}

BoolGetter is an optional interface that should be implemented by any property.Value that contains a bool

type Float

type Float float64

func (Float) Clone

func (value Float) Clone() Value

func (Float) Float

func (value Float) Float() float64

func (Float) Get

func (value Float) Get(_ string) Value

Get returns a value of the given property

func (Float) Head

func (value Float) Head() Value

Head returns the first value in a slice

func (Float) IsFloat

func (value Float) IsFloat() bool

func (Float) IsNil

func (value Float) IsNil() bool

func (Float) Len

func (value Float) Len() int

Len returns the number of elements in the value

func (Float) Map

func (value Float) Map() map[string]any

func (Float) Raw

func (value Float) Raw() any

func (Float) Set

func (value Float) Set(propertyName string, propertyValue any) Value

Set returns the value with the given property set

func (Float) String

func (value Float) String() string

func (Float) Tail

func (value Float) Tail() Value

Tail returns all values in a slice except the first

type FloatGetter

type FloatGetter interface {
	// Float returns the value typed as a float64
	Float() float64
}

FloatGetter is an optional interface that should be implemented by any property.Value that contains a float64

type Int

type Int int

func (Int) Clone

func (value Int) Clone() Value

func (Int) Get

func (value Int) Get(_ string) Value

Get returns a value of the given property

func (Int) Head

func (value Int) Head() Value

Head returns the first value in a slice

func (Int) Int

func (value Int) Int() int

func (Int) Int64

func (value Int) Int64() int64

func (Int) IsInt

func (value Int) IsInt() bool

func (Int) IsInt64

func (value Int) IsInt64() bool

func (Int) IsNil

func (value Int) IsNil() bool

func (Int) Len

func (value Int) Len() int

Len returns the number of elements in the value

func (Int) Map

func (value Int) Map() map[string]any

func (Int) Raw

func (value Int) Raw() any

func (Int) Set

func (value Int) Set(propertyName string, propertyValue any) Value

Set returns the value with the given property set

func (Int) String

func (value Int) String() string

func (Int) Tail

func (value Int) Tail() Value

Tail returns all values in a slice except the first

type Int64

type Int64 int64

func (Int64) Clone

func (value Int64) Clone() Value

func (Int64) Get

func (value Int64) Get(_ string) Value

Get returns a value of the given property

func (Int64) Head

func (value Int64) Head() Value

Head returns the first value in a slice

func (Int64) Int

func (value Int64) Int() int

func (Int64) Int64

func (value Int64) Int64() int64

func (Int64) IsInt

func (value Int64) IsInt() bool

func (Int64) IsInt64

func (value Int64) IsInt64() bool

func (Int64) IsNil

func (value Int64) IsNil() bool

func (Int64) Len

func (value Int64) Len() int

Len returns the number of elements in the value

func (Int64) Map

func (value Int64) Map() map[string]any

func (Int64) Raw

func (value Int64) Raw() any

func (Int64) Set

func (value Int64) Set(propertyName string, propertyValue any) Value

Set returns the value with the given property set

func (Int64) String

func (value Int64) String() string

func (Int64) Tail

func (value Int64) Tail() Value

Tail returns all values in a slice except the first

type Int64Getter

type Int64Getter interface {
	// Int64 returns the value typed as an int64
	Int64() int64
}

Int64Getter is an optional interface that should be implemented by any property.Value that contains an int64

type IntGetter

type IntGetter interface {
	// Int returns the value typed as an int
	Int() int
}

IntGetter is an optional interface that should be implemented by any property.Value that contains an int

type IsBooler

type IsBooler interface {
	IsBool() bool
	Bool() bool
}

type IsFloater

type IsFloater interface {
	IsFloat() bool
	Float() float64
}

type IsInt64er

type IsInt64er interface {
	IsInt64() bool
	Int64() int64
}

type IsInter

type IsInter interface {
	IsInt() bool
	Int() int
}

type IsMapper

type IsMapper interface {
	IsMap() bool
	Map() map[string]any
	MapKeys() []string
}

type IsSlicer

type IsSlicer interface {
	IsSlice() bool
	Slice() []any
}

type IsStringer

type IsStringer interface {
	IsString() bool
	String() string
}

type IsTimeer

type IsTimeer interface {
	IsTime() bool
	Time() time.Time
}

type Map

type Map map[string]any

func (Map) Clone

func (value Map) Clone() Value

func (Map) Get

func (value Map) Get(name string) Value

Get returns a value of the given property

func (Map) Head

func (value Map) Head() Value

Head returns the first value in a slice

func (Map) IsMap

func (value Map) IsMap() bool

func (Map) IsNil

func (value Map) IsNil() bool

func (Map) Len

func (value Map) Len() int

Len returns the number of elements in the value

func (Map) Map

func (value Map) Map() map[string]any

func (Map) MapKeys

func (value Map) MapKeys() []string

func (Map) Raw

func (value Map) Raw() any

func (Map) Set

func (value Map) Set(name string, newValue any) Value

Set returns the value with the given property set

func (Map) String

func (value Map) String() string

func (Map) Tail

func (value Map) Tail() Value

Tail returns all values in a slice except the first

type MapGetter

type MapGetter interface {
	// Map returns the value typed as a map[string]any
	Map() map[string]any
}

MapGetter is an optional interface that should be implemented by any property.Value that contains a map[string]any

type Nil

type Nil struct{}

func (Nil) Clone

func (value Nil) Clone() Value

func (Nil) Get

func (value Nil) Get(string) Value

Get returns a value of the given property

func (Nil) Head

func (value Nil) Head() Value

Head returns the first value in a slice

func (Nil) IsNil

func (value Nil) IsNil() bool

func (Nil) Len

func (value Nil) Len() int

Len returns the number of elements in the value

func (Nil) Map

func (value Nil) Map() map[string]any

func (Nil) Raw

func (value Nil) Raw() any

func (Nil) Set

func (value Nil) Set(string, any) Value

Set returns the value with the given property set

func (Nil) String

func (value Nil) String() string

func (Nil) Tail

func (value Nil) Tail() Value

Tail returns all values in a slice except the first

type Slice

type Slice []any

func (Slice) Clone

func (value Slice) Clone() Value

Clone returns a deep copy of the value

func (Slice) Get

func (value Slice) Get(name string) Value

Get returns a value of the given property

func (Slice) Head

func (value Slice) Head() Value

Head returns the first value in a slice

func (Slice) IsNil

func (value Slice) IsNil() bool

IsNil returns true if the value is nil

func (Slice) IsSlice

func (value Slice) IsSlice() bool

func (Slice) Len

func (value Slice) Len() int

Len returns the number of elements in the value

func (Slice) Map

func (value Slice) Map() map[string]any

Map returns the value as a map

func (Slice) Raw

func (value Slice) Raw() any

Raw returns the original wrapped value

func (Slice) Set

func (value Slice) Set(name string, newValue any) Value

Set returns the value with the given property set

func (Slice) Slice

func (value Slice) Slice() []any

func (Slice) String

func (value Slice) String() string

String returns a string representation of the value

func (Slice) Tail

func (value Slice) Tail() Value

Tail returns all values in a slice except the first

type SliceGetter

type SliceGetter interface {
	// Slice returns the value typed as a []any
	Slice() []any
}

SliceGetter is an optional interface that should be implemented by any property.Value that contains a []any

type String

type String string

func (String) Clone

func (value String) Clone() Value

Clone returns a deep copy of the value

func (String) Get

func (value String) Get(propertyName string) Value

Get returns a value of the given property

func (String) Head

func (value String) Head() Value

Head returns the first value in a slice

func (String) IsNil

func (value String) IsNil() bool

IsNil returns TRUE if the value is nil

func (String) IsString

func (value String) IsString() bool

func (String) Len

func (value String) Len() int

Len returns the number of elements in the value

func (String) Map

func (value String) Map() map[string]any

Map returns the value as a map

func (String) Raw

func (value String) Raw() any

Raw returns the raw, original value

func (String) Set

func (value String) Set(propertyName string, propertyValue any) Value

Set returns the value with the given property set

func (String) String

func (value String) String() string

String returns a string representation of the value

func (String) Tail

func (value String) Tail() Value

Tail returns all values in a slice except the first

type StringGetter

type StringGetter interface {
	// String returns the value typed as a string
	String() string
}

StringGetter is an optional interface that should be implemented by any property.Value that contains a string

type Time

type Time time.Time

func (Time) Clone

func (value Time) Clone() Value

Clone returns a deep copy of the value

func (Time) Get

func (value Time) Get(_ string) Value

Get returns a value of the given property

func (Time) Head

func (value Time) Head() Value

Head returns the first value in a slice

func (Time) IsNil

func (value Time) IsNil() bool

IsNil returns TRUE if the value is nil

func (Time) IsTime

func (value Time) IsTime() bool

func (Time) Len

func (value Time) Len() int

Len returns the number of elements in the value

func (Time) Map

func (value Time) Map() map[string]any

Map returns the value as a map[string]any

func (Time) Raw

func (value Time) Raw() any

Raw returns the raw, original value

func (Time) Set

func (value Time) Set(propertyName string, propertyValue any) Value

Set returns the value with the given property set

func (Time) String

func (value Time) String() string

String returs the string representation of the value

func (Time) Tail

func (value Time) Tail() Value

Tail returns all values in a slice except the first

func (Time) Time

func (value Time) Time() time.Time

type TimeGetter

type TimeGetter interface {
	// Time returns the value typed as a time.Time
	Time() time.Time
}

TimeGetter is an optional interface that should be implemented by any property.Value that contains a time.Time

type Value

type Value interface {

	// Get returns a value of the given property
	Get(string) Value

	// Set returns the value with the given property set
	Set(string, any) Value

	// Head returns the first value in a slices, or the value itself if it is not a slice
	Head() Value

	// Tail returns all values in a slice except the first
	Tail() Value

	// Len returns the number of elements in the value
	Len() int

	// IsNil returns TRUE if the value is empty
	IsNil() bool

	// Map returns the map representation of this value
	Map() map[string]any

	// Raw returns the raw, unwrapped value being stored
	Raw() any

	// Clone returns a deep copy of a value
	Clone() Value
}

Value is a wrapper for any kind of value that might be used in a streams.Document

func NewValue

func NewValue(value any) Value

Jump to

Keyboard shortcuts

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