syncconfig

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAuth

func ClearAuth() error

ClearAuth removes the auth.json file.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns ~/.config/td, creating it if necessary.

func GenerateDeviceID

func GenerateDeviceID() (string, error)

GenerateDeviceID creates a new random device ID (16 bytes hex).

func GetAPIKey

func GetAPIKey() string

GetAPIKey returns the API key. Priority: TD_AUTH_KEY env > auth.json.

func GetAutoSyncDebounce

func GetAutoSyncDebounce() time.Duration

GetAutoSyncDebounce returns the debounce duration for post-mutation sync. Priority: TD_SYNC_AUTO_DEBOUNCE env > config.json sync.auto.debounce > 3s

func GetAutoSyncEnabled

func GetAutoSyncEnabled() bool

GetAutoSyncEnabled returns whether auto-sync is enabled. Priority: TD_SYNC_AUTO env > config.json sync.auto.enabled > true

func GetAutoSyncInterval

func GetAutoSyncInterval() time.Duration

GetAutoSyncInterval returns the periodic sync interval. Priority: TD_SYNC_AUTO_INTERVAL env > config.json sync.auto.interval > 5m

func GetAutoSyncOnStart

func GetAutoSyncOnStart() bool

GetAutoSyncOnStart returns whether to sync on startup. Priority: TD_SYNC_AUTO_START env > config.json sync.auto.on_start > true

func GetAutoSyncPull

func GetAutoSyncPull() bool

GetAutoSyncPull returns whether auto-sync should include pull. Priority: TD_SYNC_AUTO_PULL env > config.json sync.auto.pull > true

func GetDeviceID

func GetDeviceID() (string, error)

GetDeviceID returns the device ID from auth.json, generating one if needed.

func GetServerURL

func GetServerURL() string

GetServerURL returns the sync server URL. Priority: TD_SYNC_URL env > config.json > default.

func GetSnapshotThreshold

func GetSnapshotThreshold() int

GetSnapshotThreshold returns the snapshot bootstrap threshold (min server events). Priority: TD_SYNC_SNAPSHOT_THRESHOLD env > config.json > default (100).

func IsAuthenticated

func IsAuthenticated() bool

IsAuthenticated returns true if an API key is available.

func SaveAuth

func SaveAuth(creds *AuthCredentials) error

SaveAuth writes auth credentials to ~/.config/td/auth.json (0600 perms).

func SaveConfig

func SaveConfig(cfg *Config) error

SaveConfig writes the global config to ~/.config/td/config.json.

Types

type AuthCredentials

type AuthCredentials struct {
	APIKey    string `json:"api_key"`
	UserID    string `json:"user_id"`
	Email     string `json:"email"`
	ServerURL string `json:"server_url"`
	DeviceID  string `json:"device_id"`
	ExpiresAt string `json:"expires_at"`
}

AuthCredentials stores authentication state at ~/.config/td/auth.json.

func LoadAuth

func LoadAuth() (*AuthCredentials, error)

LoadAuth reads auth credentials from ~/.config/td/auth.json.

type AutoSyncConfig

type AutoSyncConfig struct {
	Enabled  *bool  `json:"enabled,omitempty"`  // nil = default true
	OnStart  *bool  `json:"on_start,omitempty"` // nil = default true
	Debounce string `json:"debounce,omitempty"` // duration string, default "3s"
	Interval string `json:"interval,omitempty"` // duration string, default "5m"
	Pull     *bool  `json:"pull,omitempty"`     // nil = default true
}

AutoSyncConfig holds auto-sync settings.

type Config

type Config struct {
	Sync SyncConfig `json:"sync"`
}

Config is the global td config stored at ~/.config/td/config.json.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads the global config from ~/.config/td/config.json.

type SyncConfig

type SyncConfig struct {
	URL               string         `json:"url"`
	Enabled           bool           `json:"enabled"`
	SnapshotThreshold *int           `json:"snapshot_threshold,omitempty"`
	Auto              AutoSyncConfig `json:"auto"`
}

SyncConfig holds sync-related settings.

Jump to

Keyboard shortcuts

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