header

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package header provides common header types for AICR data structures.

This package defines the Header type used across recipes, snapshots, and other AICR data structures to provide consistent metadata and versioning information.

Header Structure

The Header contains standard fields for API versioning and metadata:

type Header struct {
    APIVersion string    `json:"apiVersion" yaml:"apiVersion"` // API version (e.g., "v1")
    Kind       string    `json:"kind" yaml:"kind"`             // Resource type (e.g., "Recipe", "Snapshot")
    Metadata   *Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` // Optional metadata
}

Metadata includes timestamps and version information:

type Metadata struct {
    Created time.Time              `json:"created" yaml:"created"`       // Creation timestamp
    Version string                 `json:"version,omitempty" yaml:"version,omitempty"` // Tool version
    Custom  map[string]any `json:"custom,omitempty" yaml:"custom,omitempty"`   // Custom fields
}

Usage

Create a header for a recipe:

header := header.Header{
    APIVersion: "v1",
    Kind:       "Recipe",
    Metadata: &header.Metadata{
        Created: time.Now(),
        Version: "v1.0.0",
    },
}

Create a header for a snapshot:

header := header.Header{
    APIVersion: "v1",
    Kind:       "Snapshot",
    Metadata: &header.Metadata{
        Created: time.Now(),
        Version: "v1.0.0",
        Custom: map[string]any{
            "node": "gpu-node-1",
            "cluster": "production",
        },
    },
}

Serialization

Headers serialize consistently to JSON and YAML:

{
  "apiVersion": "v1",
  "kind": "Recipe",
  "metadata": {
    "created": "2025-12-30T10:30:00Z",
    "version": "v1.0.0"
  }
}

API Versioning

The APIVersion field enables evolution of data formats:

  • v1: Current stable API
  • Future versions can add fields with backward compatibility

Tools should check APIVersion before parsing:

if header.APIVersion != "v1" {
    return fmt.Errorf("unsupported API version: %s", header.APIVersion)
}

Kind Field

The Kind field identifies the resource type:

  • Recipe: Configuration recommendations
  • Snapshot: System configuration capture
  • Bundle: Deployment artifact metadata

Custom Metadata

Custom fields enable extensibility without API version changes:

metadata.Custom = map[string]any{
    "node": "gpu-node-1",
    "cluster": "production",
    "environment": "staging",
}

Timestamps

Timestamps use RFC3339 format for consistency:

metadata.Created = time.Now().UTC()
// Serializes as: "2025-12-30T10:30:00Z"

Validation

While Header doesn't enforce validation, consumers should verify:

  • APIVersion is supported
  • Kind is recognized
  • Created timestamp is reasonable
  • Version is a valid semantic version (if present)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	// Kind is the type of the snapshot object.
	Kind Kind `json:"kind,omitempty" yaml:"kind,omitempty"`

	// APIVersion is the API version of the snapshot object.
	APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`

	// Metadata contains key-value pairs with metadata about the snapshot.
	Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

Header contains metadata and versioning information for AICR resources. It follows Kubernetes-style resource conventions with Kind, APIVersion, and Metadata fields.

func New

func New(opts ...Option) *Header

New creates a new Header instance with the provided functional options. The Metadata map is initialized automatically.

func (*Header) GetKind

func (h *Header) GetKind() Kind

GetKind returns the Kind field of the Header.

func (*Header) GetMetadata

func (h *Header) GetMetadata() map[string]string

GetMetadata returns the Metadata map of the Header.

func (*Header) Init

func (h *Header) Init(kind Kind, apiVersion string, version string)

Init initializes the Header with the specified kind, apiVersion, and version. It sets the Kind, APIVersion, and populates Metadata with timestamp and version. Uses unprefixed keys (timestamp, version) for all kinds.

func (*Header) SetKind

func (h *Header) SetKind(kind Kind)

SetKind updates the Kind field of the Header.

type Kind

type Kind string

Kind represents the type of AICR resource. All AICR resources should use these constants for consistency.

const (
	KindSnapshot         Kind = "Snapshot"
	KindRecipe           Kind = "Recipe"
	KindRecipeResult     Kind = "RecipeResult"
	KindValidationResult Kind = "ValidationResult"
)

Valid Kind constants for all AICR resource types.

func (*Kind) IsValid

func (k *Kind) IsValid() bool

IsValid checks if the Kind is one of the recognized kinds.

func (Kind) String

func (k Kind) String() string

String returns the string representation of the Kind.

type Option

type Option func(*Header)

Option is a functional option for configuring Header instances.

func WithAPIVersion

func WithAPIVersion(version string) Option

WithAPIVersion returns an Option that sets the APIVersion field of the Header. The APIVersion identifies the schema version for the resource.

func WithKind

func WithKind(kind Kind) Option

WithKind returns an Option that sets the Kind field of the Header. Kind represents the type of the resource (e.g., "Snapshot", "Recipe").

func WithMetadata

func WithMetadata(key, value string) Option

WithMetadata returns an Option that adds a metadata key-value pair to the Header. If the Metadata map is nil, it will be initialized.

Jump to

Keyboard shortcuts

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