Documentation
¶
Index ¶
- type CompileError
- type MultilineError
- type OrderedMap
- func (o *OrderedMap[K, V]) Delete(key K) bool
- func (o OrderedMap[K, V]) Entries() iter.Seq2[K, V]
- func (o OrderedMap[K, V]) Get(key K) (V, bool)
- func (o OrderedMap[K, V]) Has(key K) bool
- func (o OrderedMap[K, V]) IsZero() bool
- func (o OrderedMap[K, V]) Keys() []K
- func (o OrderedMap[K, V]) Len() int
- func (o OrderedMap[K, V]) Map() map[K]V
- func (o OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (o OrderedMap[K, V]) MustGet(key K) V
- func (o OrderedMap[K, V]) OrderedMap()
- func (o *OrderedMap[K, V]) Set(key K, value V)
- func (o *OrderedMap[K, V]) UnmarshalJSON(bytes []byte) error
- func (o *OrderedMap[K, V]) UnmarshalYAML(value *yaml.Node) error
- type SimpleStack
- type Union2
- func (ju *Union2[T0, T1]) CurrentValue() any
- func (ju *Union2[T0, T1]) IsZero() bool
- func (ju *Union2[T0, T1]) MarshalJSON() ([]byte, error)
- func (ju *Union2[T0, T1]) MarshalYAML() (any, error)
- func (ju *Union2[T0, T1]) UnmarshalJSON(bytes []byte) error
- func (ju *Union2[T0, T1]) UnmarshalYAML(value *yaml.Node) error
- type Union3
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompileError ¶
CompileError is an error that occurred during the compilation stage. Contains the failed document entity path and optionally the protocol name.
func (CompileError) Error ¶
func (c CompileError) Error() string
func (CompileError) Is ¶
func (c CompileError) Is(e error) bool
func (CompileError) Unwrap ¶
func (c CompileError) Unwrap() error
type MultilineError ¶
MultilineError is an error that contains the multiline content along with the error message.
func (MultilineError) ContentLines ¶
func (e MultilineError) ContentLines() string
ContentLines returns the multiline content with line numbers.
func (MultilineError) Error ¶
func (e MultilineError) Error() string
func (MultilineError) Unwrap ¶
func (e MultilineError) Unwrap() error
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is a map that preserves the keys insertion order.
This is a naive and inefficient implementation hastily crafted just for the project needs. It has the JSON and YAML (un)marshalling support and basic map operations. Not thread-safe.
func (*OrderedMap[K, V]) Delete ¶
func (o *OrderedMap[K, V]) Delete(key K) bool
Delete removes the key from the map and returns true if key was found.
func (OrderedMap[K, V]) Entries ¶
func (o OrderedMap[K, V]) Entries() iter.Seq2[K, V]
Entries returns an iterator over the map entries in insertion/modification order -- key-value pairs.
func (OrderedMap[K, V]) Get ¶
func (o OrderedMap[K, V]) Get(key K) (V, bool)
Get returns the value for the given key or false if the key is not found.
func (OrderedMap[K, V]) Has ¶
func (o OrderedMap[K, V]) Has(key K) bool
Has returns true if the key is found in the map.
func (OrderedMap[K, V]) IsZero ¶ added in v0.4.0
func (o OrderedMap[K, V]) IsZero() bool
IsZero returns true if the map is empty. Primarily use is to make the "omitzero" tag work in JSON/YAML serialization.
func (OrderedMap[K, V]) Keys ¶
func (o OrderedMap[K, V]) Keys() []K
Keys returns the keys of the map in the order they were added.
func (OrderedMap[K, V]) Len ¶
func (o OrderedMap[K, V]) Len() int
Len returns the number of items in the map.
func (OrderedMap[K, V]) Map ¶ added in v0.4.0
func (o OrderedMap[K, V]) Map() map[K]V
Map returns the underlying map. Note that the order of keys is not preserved in the returned map.
func (OrderedMap[K, V]) MarshalJSON ¶ added in v0.4.0
func (o OrderedMap[K, V]) MarshalJSON() ([]byte, error)
func (OrderedMap[K, V]) MustGet ¶
func (o OrderedMap[K, V]) MustGet(key K) V
MustGet returns the value for the given key or panics if the key is not found.
func (OrderedMap[K, V]) OrderedMap ¶
func (o OrderedMap[K, V]) OrderedMap()
func (*OrderedMap[K, V]) Set ¶
func (o *OrderedMap[K, V]) Set(key K, value V)
Set sets the value for a given key. Always places the entry to the last position, even if it already exists.
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (o *OrderedMap[K, V]) UnmarshalJSON(bytes []byte) error
func (*OrderedMap[K, V]) UnmarshalYAML ¶
func (o *OrderedMap[K, V]) UnmarshalYAML(value *yaml.Node) error
type SimpleStack ¶
type SimpleStack[T any] struct { // contains filtered or unexported fields }
SimpleStack is a simple stack implementation, representing the LIFO data structure.
func (*SimpleStack[T]) Items ¶
func (s *SimpleStack[T]) Items() []T
Items returns all elements of the stack starting from the bottom.
func (*SimpleStack[T]) Pop ¶
func (s *SimpleStack[T]) Pop() T
Pop removes the top element of the stack and returns it. Panics if the stack is empty.
func (*SimpleStack[T]) Push ¶
func (s *SimpleStack[T]) Push(v T)
Push adds a new element to the top of the stack.
func (*SimpleStack[T]) ReplaceTop ¶
func (s *SimpleStack[T]) ReplaceTop(v T)
ReplaceTop replaces the top element with the given value. Panics if the stack is empty.
This is an equivalent for:
stack.Pop() stack.Push(v)
func (*SimpleStack[T]) Top ¶
func (s *SimpleStack[T]) Top() T
Top returns the top element of the stack. Panics if the stack is empty.
type Union2 ¶
Union2 is a union type that can hold one of two types. Typically, this is used for handling the JSON or YAML objects, that can be marshalled/unmarshalled to different types.
The union is represented as two fields, V0 and V1. The Selector field can have a value 0 or 1, indicating which of the two fields, V0 or V1 are currently active.
Example ¶
contents := []byte(`"hello"`)
var u Union2[int, string]
if err := json.Unmarshal(contents, &u); err != nil {
panic(err)
}
fmt.Printf("%[1]T: %[1]v\n", u.CurrentValue())
switch u.Selector {
case 0:
fmt.Println("It's an integer: ", u.V0)
case 1:
fmt.Println("It's a string: ", u.V1)
}
Output: string: hello It's a string: hello
func ToUnion2 ¶
ToUnion2 converts a value to an Union2 object. If v can get converted to T0 and T1, it creates a new Union2 object with the Selector set to 0 or 1, depending on the type. If the value cannot be converted to any of the types, the function panics.
func (*Union2[T0, T1]) CurrentValue ¶
CurrentValue returns the currently active value in the union.
func (*Union2[T0, T1]) MarshalJSON ¶
func (*Union2[T0, T1]) MarshalYAML ¶
func (*Union2[T0, T1]) UnmarshalJSON ¶
type Union3 ¶
Union3 is a union type that can hold one of three types. Typically, this is used for handling the JSON or YAML objects, that can be marshalled/unmarshalled to different types.
The union is represented as three fields, V0, V1 and V2. The Selector field can have a value 0, 1 or 2, indicating which of the three fields, V0, V1 or V2 are currently active.
Example ¶
contents := []byte(`"hello"`)
var u Union3[int, string, bool]
if err := json.Unmarshal(contents, &u); err != nil {
panic(err)
}
fmt.Printf("%[1]T: %[1]v\n", u.CurrentValue())
switch u.Selector {
case 0:
fmt.Println("It's an integer: ", u.V0)
case 1:
fmt.Println("It's a string: ", u.V1)
case 2:
fmt.Println("It's a bool: ", u.V2)
}
Output: string: hello It's a string: hello
func (*Union3[T0, T1, T2]) CurrentValue ¶
CurrentValue returns the currently active value in the union.