omap

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT, MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package omap is the ordered map the whole compose pipeline runs on.

JavaScript objects remember insertion order and Bun.YAML.parse hands back exactly that, so every label list, every swarmify note and every key in compose.generated.yml comes out in the order the author wrote it. A Go map does not, and ranging one into output is the single most common way a port becomes byte-different. So a parsed document is nil | bool | int64 | float64 | string | []any | *Map, and *Map is this.

One JS quirk is reproduced on purpose: integer-like keys ("0", "1", "42") are hoisted ahead of every other key, in ascending numeric order — that is what JSON.stringify does to an object, and the facts fixture pins it ("key order is insertion order"). A document with such keys is rare in a compose file (a `ports` map, a numbered service) and exactly the case a byte-diff would catch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneValue

func CloneValue(v any) any

CloneValue deep-copies a document value.

func Parse

func Parse(data []byte) (any, error)

Parse decodes any JSON value into the document universe.

Types

type Map

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

Map is an insertion-ordered string-keyed map.

func From

func From(pairs ...any) *Map

From builds a Map from key/value pairs in the order given.

func New

func New() *Map

New returns an empty Map.

func (*Map) Clone

func (m *Map) Clone() *Map

Clone deep-copies the map: nested *Map and []any values are copied, scalars shared.

func (*Map) Delete

func (m *Map) Delete(k string)

Delete removes k if present.

func (*Map) Each

func (m *Map) Each(fn func(k string, v any))

Each calls fn for every key in JS order. Safe against mutation of the map during iteration.

func (*Map) Ensure

func (m *Map) Ensure(k string) *Map

Ensure returns the nested *Map at k, creating an empty one (appended) when absent.

func (*Map) Get

func (m *Map) Get(k string) (any, bool)

Get returns the value and whether the key exists.

func (*Map) GetMap

func (m *Map) GetMap(k string) *Map

GetMap returns the nested *Map at k, or nil when absent or not a map.

func (*Map) GetSlice

func (m *Map) GetSlice(k string) []any

GetSlice returns the []any at k, or nil.

func (*Map) GetString

func (m *Map) GetString(k string) string

GetString returns the string at k, or "" when absent or not a string.

func (*Map) Has

func (m *Map) Has(k string) bool

Has reports whether the key exists.

func (*Map) Keys

func (m *Map) Keys() []string

Keys returns the keys in JS property order: integer-like keys first, ascending; then the rest in insertion order. A copy — callers may mutate the map while ranging it.

func (*Map) Len

func (m *Map) Len() int

Len is the number of keys.

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON emits keys in JS property order. Values go through the standard encoder with HTML escaping OFF — a compose label can carry `<` or `&` and JSON.stringify leaves them alone.

func (*Map) Set

func (m *Map) Set(k string, v any)

Set stores v under k. An existing key keeps its position (JS semantics); a new one is appended.

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes an object preserving key order; nested objects become *Map, arrays []any, numbers float64 when fractional or beyond int64, else int64 — the same value universe the YAML parser produces, so a document that went to disk as JSON (compose.generated.yml, meta.json) comes back indistinguishable from one parsed from YAML.

Jump to

Keyboard shortcuts

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