Documentation
¶
Index ¶
- func GetMapOfValues(val any) map[string]any
- type Operator
- type TypeFilter
- func (tf TypeFilter[T]) Filter(vals iter.Seq[T]) iter.Seq[T]
- func (tf TypeFilter[T]) FilterAll(vals []T) []T
- func (tf TypeFilter[T]) GetExpression() string
- func (tf TypeFilter[T]) MarshalJSON() ([]byte, error)
- func (tf TypeFilter[T]) ShouldInclude(val any) bool
- func (tf TypeFilter[T]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMapOfValues ¶
GetMapOfValues takes an object and returns a map of all the fields of the object as KV pairs. Any field that is a primitive and cast down to its underlying type, to ensure that type aliases are considered equivalent to their underlying types.
Types ¶
type TypeFilter ¶
TypeFilter is an object that allows a caller to filter a list of objects by their fields, using a JSON-compatible expression language.
func NewTypeFilter ¶
func NewTypeFilter[T any]() TypeFilter[T]
NewTypeFilter creates a dynamic struct that mirrors the input type T, and can be used for filtering lists of objects of type T by the fields of T.
func NewTypeFilterFromJson ¶
func NewTypeFilterFromJson[T any](inputJson string) TypeFilter[T]
NewTypeFilterFromJson is a convenience method to create a dynamic TypeFilter struct, and instantiate an object of that type with the provided JSON string.
func (TypeFilter[T]) Filter ¶
func (tf TypeFilter[T]) Filter(vals iter.Seq[T]) iter.Seq[T]
Filter takes a sequence iterator to the filtered type T, and returns an iterator function that can be applied to that input sequence.
func (TypeFilter[T]) FilterAll ¶
func (tf TypeFilter[T]) FilterAll(vals []T) []T
FilterAll is a wrapper around Filter that accepts and returns slices instead of iterators.
func (TypeFilter[T]) GetExpression ¶
func (tf TypeFilter[T]) GetExpression() string
GetExpression turns the JSON representation of this TypeFilter object into a boolean expression that can be used in the "gval.Evaluate" library. For example, if the JSON of the TypeFilter object looks something like this:
`[{"kind": {"eq": "MOVIE"}}]`
then the equivalent expression will be something like this:
`(kind == "MOVIE")`
Note that, due to the simplistic nature of the conversion, there may be innocuous artififacts in the resulting expression, such as extra unnecessary parentheses. However, the expression will be usable and correct.
func (TypeFilter[T]) MarshalJSON ¶
func (tf TypeFilter[T]) MarshalJSON() ([]byte, error)
MarshalJSON overrides the default JSON marshal function so that the inner type is marshalled instead of the TypeFilter outer wrapper.
func (TypeFilter[T]) ShouldInclude ¶
func (tf TypeFilter[T]) ShouldInclude(val any) bool
ShouldInclude accepts an object of type T and determines whether it passes the TypeFilter for type T.
func (TypeFilter[T]) UnmarshalJSON ¶
func (tf TypeFilter[T]) UnmarshalJSON(data []byte) error
MarshalJSON overrides the default JSON unmarshal function so that the inner type is unmarshalled instead of the TypeFilter outer wrapper.