config

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyPrefix is the expected prefix for all Saber API keys.
	KeyPrefix = "sk_live_"
	// KeyLength is the total length of a valid API key (prefix + 43 chars).
	KeyLength = 51
)

Variables

This section is empty.

Functions

func APIKey

func APIKey() (string, error)

APIKey returns the active API key using the lookup order: 1. SABER_API_KEY env var 2. ~/.saber/credentials.json Returns ("", nil) if no key is configured.

func DeleteCredentials

func DeleteCredentials() error

DeleteCredentials removes ~/.saber/credentials.json. Idempotent.

func RequireAPIKey

func RequireAPIKey() (string, error)

RequireAPIKey returns the API key or exits with code 2 if not configured.

func SaveCredentials

func SaveCredentials(key string) error

SaveCredentials writes credentials to ~/.saber/credentials.json (mode 0600).

func ValidateKeyFormat

func ValidateKeyFormat(key string) error

ValidateKeyFormat checks the format of an API key without hitting the network.

Types

type Credentials

type Credentials struct {
	APIKey    string    `json:"apiKey"`
	CreatedAt time.Time `json:"createdAt"`
}

Credentials is persisted to ~/.saber/credentials.json.

func LoadCredentials

func LoadCredentials() (*Credentials, error)

LoadCredentials reads ~/.saber/credentials.json.

type ErrNotAuthenticated

type ErrNotAuthenticated struct{}

ErrNotAuthenticated is returned when no API key is found.

func (*ErrNotAuthenticated) Error

func (e *ErrNotAuthenticated) Error() string

Jump to

Keyboard shortcuts

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