store

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store keeps the server's files: config.toml (edited by people), state.json (paired devices, written by the server) and the secret store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientDialAddr added in v0.1.9

func ClientDialAddr(dir string) (addr string, ok bool)

ClientDialAddr returns where a CLI on this PC should reach the server, from [client] listen in dir/config.toml. It only reads the file, so a missing or unreadable config gives ok false and the caller keeps its default. A listen address without a host, or on all interfaces, is dialled on 127.0.0.1.

func DefaultDir

func DefaultDir() string

DefaultDir is %APPDATA%\Droidline on Windows, ~/Library/Application Support/Droidline on macOS and ~/.config/droidline elsewhere. DROIDLINE_HOME overrides it.

func SecretBackend

func SecretBackend() string

func SystemLang

func SystemLang() string

Types

type Config

type Config struct {
	Name        string  `toml:"name"`
	Lang        string  `toml:"lang"`
	OfflineWait float64 `toml:"offline_wait"`
	Agent       struct {
		Listen string `toml:"listen"`
	} `toml:"agent"`
	Client struct {
		Listen         string   `toml:"listen"`
		RequireToken   bool     `toml:"require_token"`
		AllowedOrigins []string `toml:"allowed_origins"`
	} `toml:"client"`
	Discovery struct {
		Listen string `toml:"listen"`
	} `toml:"discovery"`
	Pairing struct {
		Code bool `toml:"code"`
	} `toml:"pairing"`
	Remote struct {
		Addresses []string `toml:"addresses"`
	} `toml:"remote"`
	Relay struct {
		URL string `toml:"url"`
	} `toml:"relay"`
	OCR struct {
		Tesseract string `toml:"tesseract"`
	} `toml:"ocr"`
	Webhooks []Webhook `toml:"webhooks"`
}

type DeviceRecord

type DeviceRecord struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Pub          string `json:"pub"`
	Model        string `json:"model,omitempty"`
	Manufacturer string `json:"manufacturer,omitempty"`
	SDK          int    `json:"sdk,omitempty"`
	Release      string `json:"release,omitempty"`
	Agent        string `json:"agent,omitempty"`
	PairedAt     int64  `json:"paired_at"`
	LastSeen     int64  `json:"last_seen,omitempty"`
}

type Store

type Store struct {
	Dir    string
	Config Config
	// contains filtered or unexported fields
}

func Open

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

func (*Store) AddClientToken

func (s *Store) AddClientToken(id, token, label string) error

func (*Store) CheckClientToken

func (s *Store) CheckClientToken(token string) bool

CheckClientToken compares hashes, so the token itself is never stored.

func (*Store) ClientTokens

func (s *Store) ClientTokens() []TokenRecord

func (*Store) Device

func (s *Store) Device(id string) (DeviceRecord, bool)

func (*Store) Devices

func (s *Store) Devices() []DeviceRecord

func (*Store) PutDevice

func (s *Store) PutDevice(d DeviceRecord) error

PutDevice inserts or replaces a device record by ID.

func (*Store) RemoveClientToken

func (s *Store) RemoveClientToken(id string) (bool, error)

func (*Store) RemoveDevice

func (s *Store) RemoveDevice(id string) error

func (*Store) Secret

func (s *Store) Secret(key string) string

func (*Store) SecretKeys

func (s *Store) SecretKeys(prefix string) []string

SecretKeys lists secret names with the given prefix, sorted.

func (*Store) ServerID

func (s *Store) ServerID(newID func() string) (string, error)

func (*Store) SetRelayURL

func (s *Store) SetRelayURL(url string) error

SetRelayURL rewrites relay.url in config.toml in place so comments survive.

func (*Store) SetSecret

func (s *Store) SetSecret(key, value string) error

func (*Store) TouchDevice

func (s *Store) TouchDevice(id string, now time.Time)

TouchDevice records last-seen without rewriting the file more than once a minute.

type TokenRecord

type TokenRecord struct {
	ID      string `json:"id"`
	Hash    string `json:"hash"`
	Label   string `json:"label,omitempty"`
	Created int64  `json:"created"`
}

type Webhook

type Webhook struct {
	URL          string `toml:"url"`
	Device       string `toml:"device"`
	Package      string `toml:"package"`
	TextContains string `toml:"text_contains"`
}

Jump to

Keyboard shortcuts

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