types

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileError

type CompileError struct {
	Err   error
	Path  string
	Proto string
}

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

type MultilineError struct {
	Err     error
	Content []byte
}

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

type Union2[T0, T1 any] struct {
	V0       T0
	V1       T1
	Selector uint8
}

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

func ToUnion2[T0, T1 any](v any) *Union2[T0, T1]

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

func (ju *Union2[T0, T1]) CurrentValue() any

CurrentValue returns the currently active value in the union.

func (*Union2[T0, T1]) IsZero added in v0.4.0

func (ju *Union2[T0, T1]) IsZero() bool

func (*Union2[T0, T1]) MarshalJSON

func (ju *Union2[T0, T1]) MarshalJSON() ([]byte, error)

func (*Union2[T0, T1]) MarshalYAML

func (ju *Union2[T0, T1]) MarshalYAML() (any, error)

func (*Union2[T0, T1]) UnmarshalJSON

func (ju *Union2[T0, T1]) UnmarshalJSON(bytes []byte) error

func (*Union2[T0, T1]) UnmarshalYAML

func (ju *Union2[T0, T1]) UnmarshalYAML(value *yaml.Node) error

type Union3

type Union3[T0, T1, T2 any] struct {
	V0       T0
	V1       T1
	V2       T2
	Selector uint8
}

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

func (ju *Union3[T0, T1, T2]) CurrentValue() any

CurrentValue returns the currently active value in the union.

func (*Union3[T0, T1, T2]) MarshalJSON

func (ju *Union3[T0, T1, T2]) MarshalJSON() ([]byte, error)

func (*Union3[T0, T1, T2]) MarshalYAML

func (ju *Union3[T0, T1, T2]) MarshalYAML() (any, error)

func (*Union3[T0, T1, T2]) UnmarshalJSON

func (ju *Union3[T0, T1, T2]) UnmarshalJSON(bytes []byte) error

func (*Union3[T0, T1, T2]) UnmarshalYAML

func (ju *Union3[T0, T1, T2]) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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