ds

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry[K string, V any] struct {
	Key   K
	Value V
}

type Map

type Map[K string, V any] struct {
	// contains filtered or unexported fields
}

Map is a custom Map impementation that maintains order when adding new items and when unmarshalling from JSON and YAML.

func NewMap

func NewMap[K string, V any]() *Map[K, V]

NewMap creates a new ordered Map.

func (*Map[K, V]) Entries

func (om *Map[K, V]) Entries() []Entry[K, V]

func (*Map[K, V]) Get

func (om *Map[K, V]) Get(key K) (V, bool)

Get returns the value associated with a given key in the map. It follows the interface of the built in map type returning true/false in the second parameter to indicate if the key was found in the map.

func (*Map[K, V]) Keys

func (om *Map[K, V]) Keys() []K

Keys returns the keys int the map as a slice.

func (*Map[K, V]) MarshalJSON

func (om *Map[K, V]) MarshalJSON() ([]byte, error)

func (*Map[K, V]) MarshalYAML

func (om *Map[K, V]) MarshalYAML() (any, error)

MarshalYAML implements the yaml interface marshaler to preserve insertion order.

It returns a yaml.MapSlice rather than pre-rendered bytes so that the encoder walks the entries through its normal reflection-based encode path. That path threads the current column/indent level through nested values as it recurses. If instead we rendered this map to bytes independently (e.g. via yaml.Marshal) and returned those bytes, the resulting fragment would be parsed back into an AST at column 0 and then spliced into the parent document.

func (*Map[K, V]) Set

func (om *Map[K, V]) Set(key K, val V)

Set adds a new key/value pair and keeps track of the order in which it was added.

func (*Map[K, V]) ToBuiltInMap

func (om *Map[K, V]) ToBuiltInMap() map[K]V

ToBuiltInMap converts the custom ordered map into a built in map type, losing order guarantees

func (*Map[K, V]) UnmarshalJSON

func (om *Map[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface to enable json.Unarmshal.

func (*Map[K, V]) UnmarshalYAML

func (om *Map[K, V]) UnmarshalYAML(node ast.Node) error

UnmarshalYAML implements the yaml.Unmarshaller interface to enable yaml.Unarmshal.

type MemFS

type MemFS map[string][]byte

MemFS satisfies the fs.FS interface

func (MemFS) Open

func (m MemFS) Open(name string) (fs.File, error)

func (MemFS) Persist

func (m MemFS) Persist(targetDir string) error

Persist writes all in-memory files safely to the specified target directory on disk.

type MemFile

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

MemFile satisfies the fs.File interface

func (*MemFile) Close

func (f *MemFile) Close() error

func (*MemFile) IsDir

func (f *MemFile) IsDir() bool

func (*MemFile) ModTime

func (f *MemFile) ModTime() time.Time

func (*MemFile) Mode

func (f *MemFile) Mode() fs.FileMode

func (*MemFile) Name

func (f *MemFile) Name() string

Dummy methods below satisfy the fs.FileInfo metadata interface

func (*MemFile) Read

func (f *MemFile) Read(b []byte) (int, error)

func (*MemFile) Size

func (f *MemFile) Size() int64

func (*MemFile) Stat

func (f *MemFile) Stat() (fs.FileInfo, error)

func (*MemFile) Sys

func (f *MemFile) Sys() any

Jump to

Keyboard shortcuts

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