Package: omni

Composable, thread-safe hierarchical data model built around Atom with zero dependencies.

Package: omni

Composable, thread-safe hierarchical data model for Go, built around Atom.

Repository: https://github.com/dracory/omni

Installation

go get github.com/dracory/omni

Introduction

Omni provides a flexible, composable architecture for building structured, hierarchical data models. The core type Atom represents a node with key-value properties and child nodes.

  • Build complex, type-safe structures
  • Hierarchical parent/children relationships
  • JSON and gob serialization
  • Thread-safe operations
  • Functional options for clean configuration
  • Zero external dependencies (stdlib only)

Quick Start

package main

import (
    "fmt"
    "github.com/dracory/omni"
)

func main() {
    // Create a root atom with properties
    root := omni.NewAtom(
        omni.WithProp("type", "root"),
        omni.WithProp("version", 1),
    )

    // Add a child atom
    child := omni.NewAtom(
        omni.WithProp("name", "child-1"),
        omni.WithProp("enabled", true),
    )
    root.AddChild(child)

    // Read a property
    name, _ := child.GetString("name")
    fmt.Println(name)
}

Core Concepts

  • Atom: Node with properties and children
  • Properties: simple typed getters/setters (e.g., Set, GetString, GetInt)
  • Children: manage via AddChild, Children, etc.
  • Functional options: WithProp, WithChildren, etc.

Basic Operations

// Create atom
n := omni.NewAtom(omni.WithProp("id", "A1"))

// Set & Get
n.Set("count", 3)
count, _ := n.GetInt("count")

// Children
n.AddChild(omni.NewAtom(omni.WithProp("id", "B1")))
for _, c := range n.Children() {
    _ = c // iterate children
}

Serialization

// JSON
b, _ := omni.MarshalJSON(n)
var n2 *omni.Atom
_ = omni.UnmarshalJSON(b, &n2)

// gob (binary)
bin, _ := omni.MarshalBinary(n)
var n3 *omni.Atom
_ = omni.UnmarshalBinary(bin, &n3)

Thread Safety

All public operations are safe for concurrent use. You can mutate/read atoms from multiple goroutines.

Notes

  • Ideal for structured, hierarchical configs, documents, trees, scenes, etc.
  • Zero external dependencies; integrates well with stdlib tooling.
Menu