Documentation
¶
Overview ¶
Package sync ships local Overkill sessions to a remote backend so the user can switch machines and resume. Three backends are provided:
- file: copy to a shared filesystem path (NFS, syncthing, dropbox)
- s3: any S3-compatible bucket (AWS, R2, B2, MinIO)
- git: push session blobs to a git remote
Sessions are exported as gzipped JSON containing the full Session struct (messages, settings, ledger). Conflict resolution is last-write-wins on UpdatedAt with the loser preserved as `<id>_conflict-<ts>`.
Index ¶
- Variables
- func AutoPushIfEnabled(cfg *config.Config, mgr *Manager, sessionID string, logFn func(error))
- func DecodeSession(data []byte) (*session.Session, error)
- func EncodeSession(s *session.Session) ([]byte, error)
- func SetPushTimeout(sec int)
- type Backend
- type FileBackend
- func (f *FileBackend) Delete(ctx context.Context, id string) error
- func (f *FileBackend) List(ctx context.Context) ([]SessionMeta, error)
- func (f *FileBackend) Name() string
- func (f *FileBackend) Pull(ctx context.Context, id string) ([]byte, SessionMeta, error)
- func (f *FileBackend) Push(ctx context.Context, id string, data []byte, meta SessionMeta) error
- type GitBackend
- func (g *GitBackend) Delete(ctx context.Context, id string) error
- func (g *GitBackend) List(ctx context.Context) ([]SessionMeta, error)
- func (g *GitBackend) Name() string
- func (g *GitBackend) Pull(ctx context.Context, id string) ([]byte, SessionMeta, error)
- func (g *GitBackend) Push(ctx context.Context, id string, data []byte, meta SessionMeta) error
- type Manager
- func (m *Manager) Backend() Backend
- func (m *Manager) CloseAutoPush(ctx context.Context) error
- func (m *Manager) PullAll(ctx context.Context) (int, error)
- func (m *Manager) PullOne(ctx context.Context, id string) error
- func (m *Manager) PushAll(ctx context.Context) (int, error)
- func (m *Manager) PushOne(ctx context.Context, id string) error
- func (m *Manager) Resolve(local, remote *session.Session) (winner, loser *session.Session)
- func (m *Manager) Status(ctx context.Context) (Status, error)
- type S3Backend
- func (s *S3Backend) Delete(ctx context.Context, id string) error
- func (s *S3Backend) List(ctx context.Context) ([]SessionMeta, error)
- func (s *S3Backend) Name() string
- func (s *S3Backend) Pull(ctx context.Context, id string) ([]byte, SessionMeta, error)
- func (s *S3Backend) Push(ctx context.Context, id string, data []byte, meta SessionMeta) error
- type SessionMeta
- type Status
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("sync: session not found on backend")
ErrNotFound is returned by Pull/Delete when a session is absent.
Functions ¶
func AutoPushIfEnabled ¶
AutoPushIfEnabled queues the latest persisted state of a session. One worker belongs to each manager; a slow upload cannot silently discard the next turn or prevent a different application's manager from uploading.
func DecodeSession ¶
DecodeSession reverses EncodeSession.
func EncodeSession ¶
EncodeSession marshals + gzips a session for transport.
func SetPushTimeout ¶
func SetPushTimeout(sec int)
Types ¶
type Backend ¶
type Backend interface {
// Push uploads a single session blob + metadata.
Push(ctx context.Context, sessionID string, data []byte, meta SessionMeta) error
// Pull fetches a single session blob + metadata.
Pull(ctx context.Context, sessionID string) ([]byte, SessionMeta, error)
// List enumerates all session metadata records on the backend.
List(ctx context.Context) ([]SessionMeta, error)
// Delete removes both blob and metadata for a session.
Delete(ctx context.Context, sessionID string) error
// Name identifies the backend type (file/s3/git) for status output.
Name() string
}
Backend is the abstract sync target. All operations should respect the supplied context for cancellation/timeout.
func NewBackend ¶
func NewBackend(cfg config.SyncConfig) (Backend, error)
NewBackend constructs a Backend from config. Returns (nil, nil) if sync is disabled (cfg.Backend == "").
type FileBackend ¶
type FileBackend struct {
// contains filtered or unexported fields
}
FileBackend stores blobs/meta on a shared filesystem path. Each session is two files: <id>.json.gz (blob) and <id>.meta.json (metadata).
func NewFileBackend ¶
func NewFileBackend(cfg config.SyncFileConfig) (*FileBackend, error)
func (*FileBackend) List ¶
func (f *FileBackend) List(ctx context.Context) ([]SessionMeta, error)
func (*FileBackend) Name ¶
func (f *FileBackend) Name() string
func (*FileBackend) Pull ¶
func (f *FileBackend) Pull(ctx context.Context, id string) ([]byte, SessionMeta, error)
func (*FileBackend) Push ¶
func (f *FileBackend) Push(ctx context.Context, id string, data []byte, meta SessionMeta) error
type GitBackend ¶
type GitBackend struct {
// contains filtered or unexported fields
}
GitBackend stores blobs in a local git repo and pushes to a remote on every push. Uses the system `git` binary so we don't pull in go-git.
func NewGitBackend ¶
func NewGitBackend(cfg config.SyncGitConfig) (*GitBackend, error)
func (*GitBackend) List ¶
func (g *GitBackend) List(ctx context.Context) ([]SessionMeta, error)
func (*GitBackend) Name ¶
func (g *GitBackend) Name() string
func (*GitBackend) Pull ¶
func (g *GitBackend) Pull(ctx context.Context, id string) ([]byte, SessionMeta, error)
func (*GitBackend) Push ¶
func (g *GitBackend) Push(ctx context.Context, id string, data []byte, meta SessionMeta) error
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager couples a session.Store with a Backend and provides high-level push/pull/status operations. All methods are safe for concurrent use.
func (*Manager) CloseAutoPush ¶
CloseAutoPush stops admission and drains already queued uploads. On expiry it cancels the worker and joins it before the owner closes its session store. Backends must honor context cancellation, as required by Backend's contract.
type S3Backend ¶
type S3Backend struct {
// contains filtered or unexported fields
}
S3Backend speaks S3 through minio-go, which works against AWS S3, R2, B2, MinIO and any other S3-compatible store.
func NewS3Backend ¶
func NewS3Backend(cfg config.SyncS3Config) (*S3Backend, error)
type SessionMeta ¶
type SessionMeta struct {
ID string `json:"id"`
Title string `json:"title"`
UpdatedAt time.Time `json:"updated_at"`
MessageCount int `json:"message_count"`
OriginHost string `json:"origin_host"`
Size int `json:"size,omitempty"`
}
SessionMeta is the lightweight descriptor stored alongside each blob.