store

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(b int64) string

FormatBytes formats bytes into human-readable string.

Types

type Backup

type Backup struct {
	Filename  string `json:"filename"`
	Size      int64  `json:"size"`
	CreatedAt string `json:"created_at"`
}

Backup represents a backup file record.

type BackupStore

type BackupStore struct {
	// contains filtered or unexported fields
}

BackupStore handles backup management (listing, creation, deletion). It works with the filesystem in the configured backups directory.

func NewBackupStore

func NewBackupStore(baseDir string) *BackupStore

NewBackupStore creates a new BackupStore.

func (*BackupStore) Create

func (s *BackupStore) Create(ctx context.Context) (Backup, error)

Create generates a new backup of the core application data.

func (*BackupStore) Delete

func (s *BackupStore) Delete(ctx context.Context, filename string) error

Delete removes a backup file.

func (*BackupStore) GetPath

func (s *BackupStore) GetPath(filename string) string

GetPath returns the full path to a backup file.

func (*BackupStore) List

func (s *BackupStore) List(ctx context.Context) ([]Backup, error)

List returns all backup files, newest first.

func (*BackupStore) Restore

func (s *BackupStore) Restore(ctx context.Context, filename string) error

Restore restores data from the specified backup file.

type GeoblockCacheStore

type GeoblockCacheStore struct {
	// contains filtered or unexported fields
}

GeoblockCacheStore handles geo-block CIDR cache tracking.

func NewGeoblockCacheStore

func NewGeoblockCacheStore(db *sql.DB) *GeoblockCacheStore

NewGeoblockCacheStore creates a new GeoblockCacheStore.

func (*GeoblockCacheStore) GetCache

func (s *GeoblockCacheStore) GetCache(ctx context.Context, code string) (filePath string, downloadedAt int64, err error)

GetCache returns cached info for a country.

func (*GeoblockCacheStore) SetCache

func (s *GeoblockCacheStore) SetCache(ctx context.Context, code, filePath string) error

SetCache updates the cache info for a country.

type InstanceStore

type InstanceStore struct {
	// contains filtered or unexported fields
}

InstanceStore handles instance persistence.

func NewInstanceStore

func NewInstanceStore(db *sql.DB) *InstanceStore

NewInstanceStore creates a new InstanceStore.

func (*InstanceStore) Count added in v0.0.2

func (s *InstanceStore) Count(ctx context.Context) (int, error)

Count returns the total number of instances.

func (*InstanceStore) Create

func (s *InstanceStore) Create(ctx context.Context, inst *model.Instance) error

Create inserts a new instance.

func (*InstanceStore) Delete

func (s *InstanceStore) Delete(ctx context.Context, port int) error

Delete removes an instance by port.

func (*InstanceStore) EnsureDefaultInstance added in v0.0.2

func (s *InstanceStore) EnsureDefaultInstance(ctx context.Context, proxyPort, metricsPort int) error

EnsureDefaultInstance checks if instances table is empty and seeds it from settings.

func (*InstanceStore) GetByPort

func (s *InstanceStore) GetByPort(ctx context.Context, port int) (*model.Instance, error)

GetByPort returns a single instance by port.

func (*InstanceStore) List

func (s *InstanceStore) List(ctx context.Context) ([]model.Instance, error)

List returns all instances.

type QuotaAlertStore

type QuotaAlertStore struct {
	// contains filtered or unexported fields
}

QuotaAlertStore handles quota alert deduplication.

func NewQuotaAlertStore

func NewQuotaAlertStore(db *sql.DB) *QuotaAlertStore

NewQuotaAlertStore creates a new QuotaAlertStore.

func (*QuotaAlertStore) ClearForLabel

func (s *QuotaAlertStore) ClearForLabel(ctx context.Context, label string) error

ClearForLabel removes quota alerts when traffic is reset.

func (*QuotaAlertStore) MarkAlerted

func (s *QuotaAlertStore) MarkAlerted(ctx context.Context, label string, percent int) error

MarkAlerted records that a quota alert was sent.

func (*QuotaAlertStore) WasAlerted

func (s *QuotaAlertStore) WasAlerted(ctx context.Context, label string, percent int) (bool, error)

WasAlerted checks if a quota alert was already sent for this label+percent combo.

type SecretStore

type SecretStore struct {
	// contains filtered or unexported fields
}

SecretStore handles secret persistence in SQLite.

func NewSecretStore

func NewSecretStore(db *sql.DB) *SecretStore

NewSecretStore creates a new SecretStore.

func (*SecretStore) Count

func (s *SecretStore) Count(ctx context.Context) (int, error)

Count returns total number of secrets.

func (*SecretStore) CountEnabled

func (s *SecretStore) CountEnabled(ctx context.Context) (int, error)

CountEnabled returns the count of enabled secrets.

func (*SecretStore) Create

func (s *SecretStore) Create(ctx context.Context, sec *model.Secret) error

Create inserts a new secret.

func (*SecretStore) Delete

func (s *SecretStore) Delete(ctx context.Context, label string) error

Delete removes a secret by label.

func (*SecretStore) GetByLabel

func (s *SecretStore) GetByLabel(ctx context.Context, label string) (*model.Secret, error)

GetByLabel returns a single secret by label.

func (*SecretStore) List

func (s *SecretStore) List(ctx context.Context) ([]model.Secret, error)

List returns all secrets, optionally with traffic data.

func (*SecretStore) ListEnabledLabels

func (s *SecretStore) ListEnabledLabels(ctx context.Context) ([]string, error)

ListEnabledLabels returns labels of all enabled secrets.

func (*SecretStore) ResetAllTraffic

func (s *SecretStore) ResetAllTraffic(ctx context.Context) error

ResetAllTraffic clears traffic for all users.

func (*SecretStore) ResetTraffic

func (s *SecretStore) ResetTraffic(ctx context.Context, label string) error

ResetTraffic clears traffic for a specific user.

func (*SecretStore) Update

func (s *SecretStore) Update(ctx context.Context, sec *model.Secret) error

Update modifies an existing secret.

func (*SecretStore) UpdateTraffic

func (s *SecretStore) UpdateTraffic(ctx context.Context, label string, deltaIn, deltaOut int64) error

UpdateTraffic increments the traffic counter for a user.

type SettingsStore

type SettingsStore struct {
	// contains filtered or unexported fields
}

SettingsStore handles settings persistence.

func NewSettingsStore

func NewSettingsStore(db *sql.DB) *SettingsStore

NewSettingsStore creates a new SettingsStore.

func (*SettingsStore) Get

func (s *SettingsStore) Get(ctx context.Context, key string) (string, error)

Get reads a single setting value.

func (*SettingsStore) GetAuthPasswordHash

func (s *SettingsStore) GetAuthPasswordHash(ctx context.Context) (string, error)

GetAuthPasswordHash returns the stored bcrypt password hash.

func (*SettingsStore) GetJWTSecret

func (s *SettingsStore) GetJWTSecret(ctx context.Context) (string, error)

GetJWTSecret returns the JWT signing secret, generating one if empty.

func (*SettingsStore) Load

func (s *SettingsStore) Load(ctx context.Context) (*model.Settings, error)

Load reads all settings from the database into a Settings struct.

func (*SettingsStore) Save

func (s *SettingsStore) Save(ctx context.Context, updates map[string]string) error

Save writes a partial set of settings to the database.

func (*SettingsStore) SetAuthPasswordHash

func (s *SettingsStore) SetAuthPasswordHash(ctx context.Context, hash string) error

SetAuthPasswordHash stores the bcrypt password hash.

type SlaveStore

type SlaveStore struct {
	// contains filtered or unexported fields
}

SlaveStore handles replication slave persistence.

func NewSlaveStore

func NewSlaveStore(db *sql.DB) *SlaveStore

NewSlaveStore creates a new SlaveStore.

func (*SlaveStore) Create

func (s *SlaveStore) Create(ctx context.Context, sl *model.Slave) error

Create inserts a new slave.

func (*SlaveStore) Delete

func (s *SlaveStore) Delete(ctx context.Context, host string) error

Delete removes a slave by host.

func (*SlaveStore) GetByHost

func (s *SlaveStore) GetByHost(ctx context.Context, host string) (*model.Slave, error)

GetByHost returns a single slave by host.

func (*SlaveStore) List

func (s *SlaveStore) List(ctx context.Context) ([]model.Slave, error)

List returns all slaves.

func (*SlaveStore) UpdateStatus

func (s *SlaveStore) UpdateStatus(ctx context.Context, host, status string, lastSync int64) error

UpdateStatus updates a slave's sync status.

type TokenBlocklistStore

type TokenBlocklistStore struct {
	// contains filtered or unexported fields
}

TokenBlocklistStore handles JWT token revocation.

func NewTokenBlocklistStore

func NewTokenBlocklistStore(db *sql.DB) *TokenBlocklistStore

NewTokenBlocklistStore creates a new TokenBlocklistStore.

func (*TokenBlocklistStore) Add

func (s *TokenBlocklistStore) Add(ctx context.Context, jti string, expiresAt int64) error

Add adds a token JTI to the blocklist.

func (*TokenBlocklistStore) Cleanup

func (s *TokenBlocklistStore) Cleanup(ctx context.Context) error

Cleanup removes expired entries from the blocklist.

func (*TokenBlocklistStore) IsBlocked

func (s *TokenBlocklistStore) IsBlocked(ctx context.Context, jti string) (bool, error)

IsBlocked checks if a token JTI is in the blocklist.

type TrafficStore

type TrafficStore struct {
	// contains filtered or unexported fields
}

TrafficStore handles cumulative traffic persistence.

func NewTrafficStore

func NewTrafficStore(db *sql.DB) *TrafficStore

NewTrafficStore creates a new TrafficStore.

func (*TrafficStore) FlushTraffic

func (s *TrafficStore) FlushTraffic(ctx context.Context, global model.TrafficSnapshot, users map[string]model.TrafficSnapshot) error

FlushTraffic persists all traffic deltas in a single transaction.

func (*TrafficStore) GetAllUserSnapshots added in v0.0.4

func (s *TrafficStore) GetAllUserSnapshots(ctx context.Context) (map[string][2]int64, error)

GetAllUserSnapshots returns all user snapshots in a single query.

func (*TrafficStore) GetGlobal

func (s *TrafficStore) GetGlobal(ctx context.Context) (*model.TrafficSnapshot, error)

GetGlobal returns cumulative global traffic.

func (*TrafficStore) GetUserSnapshot

func (s *TrafficStore) GetUserSnapshot(ctx context.Context, label string) (snapIn, snapOut int64, err error)

GetUserSnapshot returns the raw Prometheus snapshot for a user.

func (*TrafficStore) GetUserTraffic

func (s *TrafficStore) GetUserTraffic(ctx context.Context, label string) (*model.UserTraffic, error)

GetUserTraffic returns traffic for a specific user.

func (*TrafficStore) ListUserTraffic

func (s *TrafficStore) ListUserTraffic(ctx context.Context) ([]model.UserTraffic, error)

ListUserTraffic returns all per-user traffic stats.

func (*TrafficStore) ResetGlobal

func (s *TrafficStore) ResetGlobal(ctx context.Context) error

ResetGlobal clears global traffic counters.

func (*TrafficStore) UpdateGlobal

func (s *TrafficStore) UpdateGlobal(ctx context.Context, deltaIn, deltaOut, snapIn, snapOut int64) error

UpdateGlobal adds deltas to global traffic and updates the snapshot.

func (*TrafficStore) UpdateUserTraffic

func (s *TrafficStore) UpdateUserTraffic(ctx context.Context, label string, deltaIn, deltaOut, snapIn, snapOut int64) error

UpdateUserTraffic adds deltas to a user's traffic and updates the snapshot.

type UpstreamStore

type UpstreamStore struct {
	// contains filtered or unexported fields
}

UpstreamStore handles upstream persistence.

func NewUpstreamStore

func NewUpstreamStore(db *sql.DB) *UpstreamStore

NewUpstreamStore creates a new UpstreamStore.

func (*UpstreamStore) Create

func (s *UpstreamStore) Create(ctx context.Context, u *model.Upstream) error

Create inserts a new upstream.

func (*UpstreamStore) Delete

func (s *UpstreamStore) Delete(ctx context.Context, name string) error

Delete removes an upstream by name.

func (*UpstreamStore) GetByName

func (s *UpstreamStore) GetByName(ctx context.Context, name string) (*model.Upstream, error)

GetByName returns a single upstream by name.

func (*UpstreamStore) List

func (s *UpstreamStore) List(ctx context.Context) ([]model.Upstream, error)

List returns all upstreams.

func (*UpstreamStore) Update added in v0.0.7

func (s *UpstreamStore) Update(ctx context.Context, name string, u *model.Upstream) error

Update modifies an existing upstream identified by name.

func (*UpstreamStore) UpdateEnabled

func (s *UpstreamStore) UpdateEnabled(ctx context.Context, name string, enabled bool) error

UpdateEnabled toggles an upstream's enabled state.

Jump to

Keyboard shortcuts

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