sqlite

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sqlite implements the expose data store backed by a SQLite database. It manages API keys, domains, tunnels, connect tokens, and server settings.

Index

Constants

This section is empty.

Variables

View Source
var ErrHostnameInUse = errors.New("hostname already in use")

ErrHostnameInUse is returned when the requested hostname is already allocated by another key or tunnel type and cannot be claimed by the caller.

Functions

This section is empty.

Types

type OpenOptions added in v0.4.0

type OpenOptions struct {
	MaxOpenConns int
	MaxIdleConns int
}

OpenOptions controls SQLite connection pool sizing.

type Store

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

Store wraps a SQLite database connection for all expose persistence operations.

func Open

func Open(path string) (*Store, error)

Open creates or opens the SQLite database at path, runs migrations, and enables WAL mode for improved concurrent read performance.

func OpenWithOptions added in v0.4.0

func OpenWithOptions(path string, opts OpenOptions) (*Store, error)

OpenWithOptions creates or opens the SQLite database at path with tunable connection pool settings, runs migrations, and enables WAL mode.

func (*Store) ActiveTunnelCountByKey

func (s *Store) ActiveTunnelCountByKey(ctx context.Context, keyID string) (int, error)

func (*Store) AllocateDomainAndTunnel

func (s *Store) AllocateDomainAndTunnel(ctx context.Context, keyID, mode, subdomain, baseDomain string) (domain.Domain, domain.Tunnel, error)

func (*Store) AllocateDomainAndTunnelWithClientMeta

func (s *Store) AllocateDomainAndTunnelWithClientMeta(ctx context.Context, keyID, mode, subdomain, baseDomain, clientMeta string) (domain.Domain, domain.Tunnel, error)

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CloseTemporaryTunnel

func (s *Store) CloseTemporaryTunnel(ctx context.Context, tunnelID string) (string, bool, error)

func (*Store) ConsumeConnectToken

func (s *Store) ConsumeConnectToken(ctx context.Context, token string) (string, error)

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, name, keyHash string) (domain.APIKey, error)

func (*Store) CreateAPIKeyWithLimit added in v0.12.0

func (s *Store) CreateAPIKeyWithLimit(ctx context.Context, name, keyHash string, tunnelLimit int) (domain.APIKey, error)

func (*Store) CreateConnectToken

func (s *Store) CreateConnectToken(ctx context.Context, tunnelID string, ttl time.Duration) (string, error)

func (*Store) FindRouteByHost

func (s *Store) FindRouteByHost(ctx context.Context, host string) (domain.TunnelRoute, error)

func (*Store) GetAPIKeyTunnelLimit added in v0.12.0

func (s *Store) GetAPIKeyTunnelLimit(ctx context.Context, keyID string) (int, error)

GetAPIKeyTunnelLimit returns the per-key tunnel limit for the given key ID. A value of -1 means unlimited.

func (*Store) GetServerPepper

func (s *Store) GetServerPepper(ctx context.Context) (string, bool, error)

func (*Store) IsHostnameActive

func (s *Store) IsHostnameActive(ctx context.Context, host string) (bool, error)

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys(ctx context.Context) ([]domain.APIKey, error)

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate creates all required tables and indexes if they do not already exist.

func (*Store) PurgeInactiveTemporaryDomains

func (s *Store) PurgeInactiveTemporaryDomains(ctx context.Context, olderThan time.Time, limit int) ([]string, error)

func (*Store) PurgeStaleConnectTokens added in v0.4.0

func (s *Store) PurgeStaleConnectTokens(ctx context.Context, now, usedOlderThan time.Time, limit int) (int64, error)

PurgeStaleConnectTokens removes expired tokens and used tokens older than the provided cutoff. It limits each run to avoid long write transactions.

func (*Store) ResetConnectedTunnels

func (s *Store) ResetConnectedTunnels(ctx context.Context) (int64, error)

func (*Store) ResolveAPIKeyID

func (s *Store) ResolveAPIKeyID(ctx context.Context, keyHash string) (string, error)

func (*Store) ResolveServerPepper

func (s *Store) ResolveServerPepper(ctx context.Context, suggested string) (string, error)

func (*Store) RevokeAPIKey

func (s *Store) RevokeAPIKey(ctx context.Context, id string) error

func (*Store) SetAPIKeyTunnelLimit added in v0.12.0

func (s *Store) SetAPIKeyTunnelLimit(ctx context.Context, keyID string, limit int) error

SetAPIKeyTunnelLimit updates the per-key tunnel limit. Use -1 for unlimited.

func (*Store) SetTunnelAccessCredentials added in v0.5.0

func (s *Store) SetTunnelAccessCredentials(ctx context.Context, tunnelID, user, mode, hash string) error

func (*Store) SetTunnelAccessPasswordHash added in v0.5.0

func (s *Store) SetTunnelAccessPasswordHash(ctx context.Context, tunnelID, hash string) error

func (*Store) SetTunnelConnected

func (s *Store) SetTunnelConnected(ctx context.Context, tunnelID string) error

func (*Store) SetTunnelDisconnected

func (s *Store) SetTunnelDisconnected(ctx context.Context, tunnelID string) error

func (*Store) SwapTunnelSession

func (s *Store) SwapTunnelSession(ctx context.Context, domainID, keyID, clientMeta string) (domain.Tunnel, error)

func (*Store) TouchDomain

func (s *Store) TouchDomain(ctx context.Context, domainID string) error

func (*Store) TrySetTunnelConnected added in v0.16.0

func (s *Store) TrySetTunnelConnected(ctx context.Context, tunnelID string) error

Jump to

Keyboard shortcuts

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