domain

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 8 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")

	// Application errors
	ErrApplicationNotFound  = errors.New("application not found")
	ErrInvalidApplicationID = errors.New("invalid application ID")
	ErrInvalidAppSlug       = errors.New("invalid application slug")
	ErrInvalidGitHubURL     = errors.New("invalid GitHub URL")
	ErrInvalidApplication   = errors.New("invalid application")

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

Functions

This section is empty.

Types

type AppSlug added in v1.2.0

type AppSlug string

AppSlug is a validated, URL-safe application slug.

func NewAppSlug added in v1.2.0

func NewAppSlug(slug string) (AppSlug, error)

NewAppSlug creates and validates an AppSlug.

func Slugify added in v1.2.0

func Slugify(s string) AppSlug

Slugify converts a string to a valid slug format.

func (AppSlug) String added in v1.2.0

func (s AppSlug) String() string

String returns the string representation.

type Application added in v1.2.0

type Application struct {
	ID             ApplicationID
	Slug           AppSlug
	Name           string
	GitHubURL      GitHubURL
	Stars          int
	StarsUpdatedAt *time.Time
	LogoURL        string // Optional custom logo
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Application represents an application that can have multiple instances.

func NewApplication added in v1.2.0

func NewApplication(slug, name string) (*Application, error)

NewApplication creates a new Application with validation.

func (*Application) NeedsStarsRefresh added in v1.2.0

func (a *Application) NeedsStarsRefresh() bool

NeedsStarsRefresh returns true if stars data is stale (older than 1 hour).

func (*Application) SetGitHubURL added in v1.2.0

func (a *Application) SetGitHubURL(urlStr string) error

SetGitHubURL updates the GitHub repository URL.

func (*Application) SetLogoURL added in v1.2.0

func (a *Application) SetLogoURL(logoURL string)

SetLogoURL updates the custom logo URL.

func (*Application) UpdateStars added in v1.2.0

func (a *Application) UpdateStars(stars int)

UpdateStars updates the GitHub stars count and timestamp.

type ApplicationID added in v1.2.0

type ApplicationID string

ApplicationID is a validated application identifier (UUID format).

func NewApplicationID added in v1.2.0

func NewApplicationID(id string) (ApplicationID, error)

NewApplicationID creates and validates an ApplicationID.

func (ApplicationID) String added in v1.2.0

func (id ApplicationID) String() string

String returns the string representation.

type GitHubURL added in v1.2.0

type GitHubURL string

GitHubURL is a validated GitHub repository URL.

func NewGitHubURL added in v1.2.0

func NewGitHubURL(urlStr string) (GitHubURL, error)

NewGitHubURL creates and validates a GitHubURL.

func (GitHubURL) OwnerAndRepo added in v1.2.0

func (u GitHubURL) OwnerAndRepo() (owner, repo string, err error)

OwnerAndRepo extracts the owner and repository name from the URL.

func (GitHubURL) String added in v1.2.0

func (u GitHubURL) String() string

String returns the string representation.

type Instance

type Instance struct {
	ID             InstanceID
	PublicKey      PublicKey
	ApplicationID  ApplicationID // Foreign key to applications table
	AppName        string        // Denormalized for compatibility
	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