Documentation
¶
Overview ¶
Package syncserver implements the cloud-sync HTTP endpoints described in docs/adr/0001-wordbank-history-sync.md.
The transport is HTTP REST + JSON (ADR D5) and authentication is a single HTTP Basic Auth credential pair (ADR D4). All sync data lives under a per-user directory:
<dataDir>/<user>/wordbank.db <dataDir>/<user>/history.db
A SyncServer is mounted by registering it onto an existing *gin.Engine via Mount(). The endpoints all live under the /sync/v1 prefix and reuse the host server's middleware stack (logger, recovery, etc.).
Index ¶
Constants ¶
const SchemaVersion = 1
SchemaVersion is the wire-protocol version. Bumped whenever the JSON shape of a sync request or response changes incompatibly.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DataDir is the directory containing per-user subdirectories. Each
// user has their own wordbank.db / history.db inside <DataDir>/<user>/.
DataDir string
// Username and Password are the Basic Auth credentials. Both must be
// non-empty; an empty credential disables the server (Mount returns an
// error). Compared with constant-time equality.
Username string
Password string
}
Config configures a SyncServer.
type SyncServer ¶
type SyncServer struct {
// contains filtered or unexported fields
}
SyncServer is the gin-mountable sync handler.
Per-user stores are opened lazily on first use and cached in memory; we never re-open the same SQLite DB twice. Concurrent requests for the same user share a single store handle (database/sql provides its own connection pool).
func New ¶
func New(cfg Config) (*SyncServer, error)
New constructs a SyncServer. Returns an error if Config is invalid.
func (*SyncServer) Close ¶
func (s *SyncServer) Close() error
Close releases every cached per-user store handle.
func (*SyncServer) Mount ¶
func (s *SyncServer) Mount(r *gin.Engine)
Mount registers the sync routes on r under /sync/v1 with Basic Auth.