types

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package types provides type-safe enumerations and constants for xg2g.

This package centralizes all typed constants, enums, and state types to prevent string-based bugs and improve code maintainability.

Package types provides common data types used across the xg2g application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FeatureFlag

type FeatureFlag string

FeatureFlag represents a feature toggle in the application.

const (
	// FeatureFlagAudioTranscoding enables audio transcoding via FFmpeg.
	FeatureFlagAudioTranscoding FeatureFlag = "AUDIO_TRANSCODING"

	// FeatureFlagGPUTranscode enables GPU-accelerated video transcoding.
	FeatureFlagGPUTranscode FeatureFlag = "GPU_TRANSCODE"

	// FeatureFlagEPG enables Electronic Program Guide fetching.
	FeatureFlagEPG FeatureFlag = "EPG"

	// FeatureFlagAPIv2 enables experimental API v2 endpoints.
	FeatureFlagAPIv2 FeatureFlag = "APIv2"

	// FeatureFlagTelemetry enables OpenTelemetry distributed tracing.
	FeatureFlagTelemetry FeatureFlag = "TELEMETRY"

	// FeatureFlagMetrics enables Prometheus metrics collection.
	FeatureFlagMetrics FeatureFlag = "METRICS"
)

Feature flag constants define all available feature toggles.

func AllFeatureFlags

func AllFeatureFlags() []FeatureFlag

AllFeatureFlags returns all defined feature flags.

func (FeatureFlag) EnvVarName

func (f FeatureFlag) EnvVarName() string

EnvVarName returns the environment variable name for this feature flag.

Example: FeatureFlagEPG.EnvVarName() returns "XG2G_EPG_ENABLED"

func (FeatureFlag) IsValid

func (f FeatureFlag) IsValid() bool

IsValid checks whether the feature flag is defined.

func (FeatureFlag) String

func (f FeatureFlag) String() string

String implements fmt.Stringer.

type JobStatus

type JobStatus string

JobStatus represents the current state of a background job.

JobStatus provides type safety for job state management, preventing string-based typos and enabling exhaustive switch statements.

const (
	// JobStatusPending indicates the job is queued but not yet started.
	JobStatusPending JobStatus = "pending"

	// JobStatusRunning indicates the job is currently executing.
	JobStatusRunning JobStatus = "running"

	// JobStatusCompleted indicates the job finished successfully.
	JobStatusCompleted JobStatus = "completed"

	// JobStatusFailed indicates the job encountered an error and terminated.
	JobStatusFailed JobStatus = "failed"

	// JobStatusCancelled indicates the job was manually cancelled.
	JobStatusCancelled JobStatus = "cancelled"
)

Job status constants define all possible states of a background job.

func AllJobStatuses

func AllJobStatuses() []JobStatus

AllJobStatuses returns all defined job statuses.

Useful for validation, documentation, and UI enumeration.

func ParseJobStatus

func ParseJobStatus(s string) (JobStatus, error)

ParseJobStatus parses a string into a JobStatus, returning an error if invalid.

Example:

status, err := ParseJobStatus("running")
if err != nil {
    // Handle invalid status
}

func (JobStatus) CanTransitionTo

func (s JobStatus) CanTransitionTo(target JobStatus) bool

CanTransitionTo checks whether this status can transition to the target status.

Valid transitions:

  • Pending → Running, Cancelled
  • Running → Completed, Failed, Cancelled
  • Terminal states cannot transition

Example:

current := JobStatusPending
if current.CanTransitionTo(JobStatusRunning) {
    // Safe to transition
}

func (JobStatus) IsTerminal

func (s JobStatus) IsTerminal() bool

IsTerminal checks whether the job status represents a final state.

Terminal states include: Completed, Failed, Cancelled. A job in a terminal state will not transition to another state.

Example:

if status.IsTerminal() {
    // Job is done, cleanup resources
}

func (JobStatus) IsValid

func (s JobStatus) IsValid() bool

IsValid checks whether the job status is one of the defined constants.

Returns true if the status is valid, false otherwise.

Example:

status := JobStatus("running")
if status.IsValid() {
    // Safe to use
}

func (JobStatus) MarshalJSON

func (s JobStatus) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for JobStatus.

func (JobStatus) String

func (s JobStatus) String() string

String returns the string representation of the job status. Implements the fmt.Stringer interface for better logging and debugging.

func (*JobStatus) UnmarshalJSON

func (s *JobStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for JobStatus.

type StreamState

type StreamState string

StreamState represents the current state of a media stream.

const (
	// StreamStateIdle indicates no stream is active.
	StreamStateIdle StreamState = "idle"

	// StreamStateConnecting indicates the stream is establishing connection.
	StreamStateConnecting StreamState = "connecting"

	// StreamStateBuffering indicates the stream is buffering data.
	StreamStateBuffering StreamState = "buffering"

	// StreamStateStreaming indicates the stream is actively transmitting.
	StreamStateStreaming StreamState = "streaming"

	// StreamStateTranscoding indicates the stream is being transcoded.
	StreamStateTranscoding StreamState = "transcoding"

	// StreamStateError indicates the stream encountered an error.
	StreamStateError StreamState = "error"

	// StreamStateStopped indicates the stream was stopped.
	StreamStateStopped StreamState = "stopped"
)

Stream state constants define all possible states of a media stream.

func AllStreamStates

func AllStreamStates() []StreamState

AllStreamStates returns all defined stream states.

func ParseStreamState

func ParseStreamState(s string) (StreamState, error)

ParseStreamState parses a string into a StreamState.

func (StreamState) IsActive

func (s StreamState) IsActive() bool

IsActive checks whether the stream is in an active state.

func (StreamState) IsValid

func (s StreamState) IsValid() bool

IsValid checks whether the stream state is valid.

func (StreamState) MarshalJSON

func (s StreamState) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (StreamState) String

func (s StreamState) String() string

String implements fmt.Stringer.

func (*StreamState) UnmarshalJSON

func (s *StreamState) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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