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 ¶
- func CloneValue(v any) any
- func Parse(data []byte) (any, error)
- type Map
- func (m *Map) Clone() *Map
- func (m *Map) Delete(k string)
- func (m *Map) Each(fn func(k string, v any))
- func (m *Map) Ensure(k string) *Map
- func (m *Map) Get(k string) (any, bool)
- func (m *Map) GetMap(k string) *Map
- func (m *Map) GetSlice(k string) []any
- func (m *Map) GetString(k string) string
- func (m *Map) Has(k string) bool
- func (m *Map) Keys() []string
- func (m *Map) Len() int
- func (m *Map) MarshalJSON() ([]byte, error)
- func (m *Map) Set(k string, v any)
- func (m *Map) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is an insertion-ordered string-keyed map.
func (*Map) Clone ¶
Clone deep-copies the map: nested *Map and []any values are copied, scalars shared.
func (*Map) Each ¶
Each calls fn for every key in JS order. Safe against mutation of the map during iteration.
func (*Map) Ensure ¶
Ensure returns the nested *Map at k, creating an empty one (appended) when absent.
func (*Map) Keys ¶
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) MarshalJSON ¶
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 ¶
Set stores v under k. An existing key keeps its position (JS semantics); a new one is appended.
func (*Map) UnmarshalJSON ¶
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.