dd_11_pointers

command
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 3 Imported by: 0

README

pointer references example

this example demonstrates how to use df.Pointer[T] for object references that support cycles and type safety.

key concepts

  • Identifiable interface: objects implement GetId() string to participate in pointer references
  • Pointer[T] type: generic type that holds references like *df.Pointer[*User]
  • two-phase process:
    1. df.Bind() - loads data and stores $ref strings
    2. df.Link() - resolves all references to actual objects
  • type namespacing: objects with same ID but different types don't clash (e.g., User:1 vs Document:1)

usage

go run main.go

JSON structure

the example uses this data structure with $ref fields:

{
  "users": [
    {"id": "user1", "name": "Alice Johnson", "age": 28},
    {"id": "user2", "name": "Bob Smith", "age": 35}
  ],
  "documents": [
    {
      "id": "doc1", 
      "title": "Go Programming Guide",
      "author": {"$ref": "user1"},
      "editor": {"$ref": "user2"}
    }
  ]
}

the $ref values are resolved to actual object pointers during the Link phase.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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