domain

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Instance errors
	ErrInstanceNotFound        = errors.New("instance not found")
	ErrInstanceRevoked         = errors.New("instance is revoked")
	ErrInvalidInstanceID       = errors.New("invalid instance ID")
	ErrInvalidPublicKey        = errors.New("invalid public key")
	ErrInvalidInstance         = errors.New("invalid instance")
	ErrInvalidStatusTransition = errors.New("invalid status transition")

	// Snapshot errors
	ErrInvalidSnapshot = errors.New("invalid snapshot")
	ErrInvalidMetrics  = errors.New("invalid metrics")

	// Authentication errors
	ErrInvalidSignature = errors.New("invalid signature")
	ErrMissingSignature = errors.New("missing signature")
)

Functions

This section is empty.

Types

type Instance

type Instance struct {
	ID             InstanceID
	PublicKey      PublicKey
	AppName        string
	AppVersion     string
	DeploymentMode string
	Environment    string
	OSArch         string
	Status         InstanceStatus
	LastSeenAt     time.Time
	CreatedAt      time.Time
}

Instance represents a registered telemetry client instance.

func NewInstance

func NewInstance(
	instanceID string,
	publicKey string,
	appName string,
	appVersion string,
	deploymentMode string,
	environment string,
	osArch string,
) (*Instance, error)

NewInstance creates a new Instance with validation.

func (*Instance) Activate

func (i *Instance) Activate() error

Activate transitions the instance to active status.

func (*Instance) IsActive

func (i *Instance) IsActive() bool

IsActive returns true if the instance is in active status.

func (*Instance) IsRevoked

func (i *Instance) IsRevoked() bool

IsRevoked returns true if the instance is revoked.

func (*Instance) Revoke

func (i *Instance) Revoke() error

Revoke transitions the instance to revoked status.

func (*Instance) UpdateHeartbeat

func (i *Instance) UpdateHeartbeat()

UpdateHeartbeat updates the last seen timestamp.

type InstanceID

type InstanceID string

InstanceID is a validated instance identifier (UUID format).

func NewInstanceID

func NewInstanceID(id string) (InstanceID, error)

NewInstanceID creates and validates an InstanceID.

func (InstanceID) String

func (id InstanceID) String() string

String returns the string representation.

type InstanceStatus

type InstanceStatus string

InstanceStatus represents the lifecycle state of an instance.

const (
	StatusPending InstanceStatus = "pending"
	StatusActive  InstanceStatus = "active"
	StatusRevoked InstanceStatus = "revoked"
)

func (InstanceStatus) CanTransitionTo

func (s InstanceStatus) CanTransitionTo(target InstanceStatus) bool

CanTransitionTo checks if a status transition is allowed.

func (InstanceStatus) Valid

func (s InstanceStatus) Valid() bool

Valid returns true if the status is a known value.

type Metrics

type Metrics map[string]any

Metrics represents schema-agnostic telemetry data. Stored as JSON, can contain any numeric or string values.

func NewMetrics

func NewMetrics(raw json.RawMessage) (Metrics, error)

NewMetrics creates Metrics from raw JSON bytes.

func (Metrics) GetFloat64

func (m Metrics) GetFloat64(key string) (float64, bool)

GetFloat64 retrieves a numeric metric value. Returns 0 and false if the key doesn't exist or isn't numeric.

func (Metrics) GetString

func (m Metrics) GetString(key string) (string, bool)

GetString retrieves a string metric value.

func (Metrics) Raw

func (m Metrics) Raw() (json.RawMessage, error)

Raw returns the JSON representation of the metrics.

func (Metrics) SumNumeric

func (m Metrics) SumNumeric() map[string]float64

SumNumeric returns the sum of all numeric values in the metrics.

type PublicKey

type PublicKey string

PublicKey is a hex-encoded Ed25519 public key.

func NewPublicKey

func NewPublicKey(key string) (PublicKey, error)

NewPublicKey creates and validates a PublicKey.

func (PublicKey) String

func (pk PublicKey) String() string

String returns the string representation.

type Snapshot

type Snapshot struct {
	ID         int64
	InstanceID InstanceID
	SnapshotAt time.Time
	Metrics    Metrics
}

Snapshot represents a point-in-time telemetry capture from an instance.

func NewSnapshot

func NewSnapshot(instanceID string, timestamp time.Time, metrics json.RawMessage) (*Snapshot, error)

NewSnapshot creates a new Snapshot with validation.

func (*Snapshot) Age

func (s *Snapshot) Age() time.Duration

Age returns how old the snapshot is.

Jump to

Keyboard shortcuts

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