memstore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: ? 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 memstore keeps a server's tickets (Store) and attachments (Files) in memory: for tests, and for trying the framework out. Everything is lost when the process ends. It reads back what it is given as the PostgreSQL store does, the times too: to the microsecond, what is finer cut off, and in UTC (us), so that what is tried on it orders and leases as it would on PostgreSQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Files

type Files struct {
	Base string
	// contains filtered or unexported fields
}

Files is a server.Files in memory: the attachments of a server that keeps its tickets in memory. With a Base, URL answers Base/<id> (as a store that serves its own bytes would); without one, "" (the server sends them). Everything is lost when the process ends.

func (*Files) Delete

func (f *Files) Delete(_ context.Context, id string) error

Delete deletes a file.

func (*Files) Has

func (f *Files) Has(id string) bool

Has reports whether a file is kept.

func (*Files) Len

func (f *Files) Len() int

Len answers how many files are kept.

func (*Files) Open

Open reads a file.

func (*Files) Put

func (f *Files) Put(_ context.Context, info server.FileInfo, r io.Reader) (string, error)

Put keeps a file and answers its ID: 32 hexadecimal digits. A file with no time (FileInfo.At) is kept with the time it is put, as the other Files keep it; the time is kept to the microsecond, as PostgreSQL keeps it (us).

func (*Files) Stat

func (f *Files) Stat(_ context.Context, id string) (server.FileInfo, error)

Stat answers what is kept of a file.

func (*Files) URL

func (f *Files) URL(_ context.Context, id string) (string, error)

URL answers Base/<id>, or "" with no Base.

type Store

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

Store is a store in memory. Its zero value is not ready; use New.

func New

func New() *Store

New makes an empty store.

func (*Store) Begin

func (s *Store) Begin(_ context.Context, b server.Begun) (server.Begun, error)

Begin keeps an operation the first time its key is given, and answers what is kept.

func (*Store) BundleArchive

func (s *Store) BundleArchive(_ context.Context, digest string) ([]byte, error)

BundleArchive reads a bundle's archive, or ErrNotFound.

func (*Store) Bundles

func (s *Store) Bundles(_ context.Context) ([]server.Bundle, error)

Bundles reads every bundle the store keeps, without their archives, in the order they were kept.

func (*Store) CountMine

func (s *Store) CountMine(_ context.Context, person string) (map[string]server.MineCount, error)

CountMine counts a person's own tickets, by kind and by state.

func (*Store) CountTickets

func (s *Store) CountTickets(_ context.Context, versions []server.KindVersion) ([]server.TicketCount, error)

CountTickets counts the tickets of the versions given by kind, version and status.

func (*Store) CountWaiting

func (s *Store) CountWaiting(_ context.Context, person string) (map[string]int, error)

CountWaiting counts the tickets that wait for the person, by kind.

func (*Store) DoneToDo

func (s *Store) DoneToDo(_ context.Context, id string, at time.Time) error

DoneToDo marks one done.

func (*Store) Draft

func (s *Store) Draft(_ context.Context, person, id string) (server.Draft, error)

Draft reads a person's draft.

func (*Store) DueTimers

func (s *Store) DueTimers(_ context.Context, now time.Time, lease time.Duration, limit int) ([]server.Timer, error)

DueTimers leases the timers that are due.

func (*Store) DueToDo

func (s *Store) DueToDo(_ context.Context, now time.Time, lease time.Duration, limit int) ([]server.ToDo, error)

DueToDo leases the things to do that are due.

func (*Store) ForgetDrafts

func (s *Store) ForgetDrafts(_ context.Context, before time.Time, limit int) (int, error)

ForgetDrafts forgets up to limit drafts kept before `before`, the oldest first.

func (*Store) ForgetOperations

func (s *Store) ForgetOperations(_ context.Context, before time.Time, limit int) (int, error)

ForgetOperations forgets up to limit operations answered before `before` and up to limit operations begun before it whose reply was never kept, the oldest first of each, and answers how many of both. Of one time, it forgets them by person, then by key, as Go compares strings (Store.ForgetOperations).

func (*Store) Imports

func (s *Store) Imports(_ context.Context, since time.Time) ([]time.Time, error)

Imports answers the times of the imports that added a snapshot at or after since.

func (*Store) KeepDraft

func (s *Store) KeepDraft(_ context.Context, d server.Draft, max int) error

KeepDraft keeps a draft, forgetting the person's oldest past max.

func (*Store) KeepOutcome

func (s *Store) KeepOutcome(_ context.Context, id string, at time.Time, outcome json.RawMessage) error

KeepOutcome keeps what the work of one said became of it, in place of what it said before.

func (*Store) KeepToDo

func (s *Store) KeepToDo(_ context.Context, td server.ToDo) error

KeepToDo keeps a thing to do that no move holds; one with the same ID is left as it is.

func (*Store) KeepUpload

func (s *Store) KeepUpload(_ context.Context, u server.Upload, max int) (string, error)

KeepUpload records an upload, unless the person has one with its key, or max uploads no ticket holds.

func (*Store) KeptVersions

func (s *Store) KeptVersions(context.Context) ([]server.TicketCount, error)

KeptVersions counts the tickets of every version the store keeps any of, by kind, version and status.

func (*Store) LastImport

func (s *Store) LastImport(context.Context) (server.Record, error)

LastImport reads the latest record of an import from the source.

func (*Store) LatestOrganization

func (s *Store) LatestOrganization(_ context.Context) (server.OrgSnapshot, error)

LatestOrganization reads the latest snapshot.

func (*Store) LetGoUploads

func (s *Store) LetGoUploads(_ context.Context, before time.Time, limit int) ([]server.Upload, error)

LetGoUploads lets go of the oldest uploads made before `before` that no ticket holds, and answers them after the ones let go earlier whose files are not deleted yet.

func (*Store) Lock

func (s *Store) Lock(ctx context.Context, ticket string) (context.Context, func(), error)

Lock takes a ticket's lock.

func (*Store) Mine

func (s *Store) Mine(_ context.Context, person string, q server.MineQuery) ([]server.TicketRecord, error)

Mine reads a person's own tickets, the newest first.

func (*Store) Moves

func (s *Store) Moves(_ context.Context, ticket string) ([]server.MoveRecord, error)

Moves reads a ticket's moves.

func (*Store) OpenUploads

func (s *Store) OpenUploads(_ context.Context, person string) (int, error)

OpenUploads counts a person's uploads that no ticket holds and that are not let go.

func (*Store) Operation

func (s *Store) Operation(_ context.Context, person, key string) (server.OperationRecord, error)

Operation reads what was answered to a key.

func (*Store) Organization

func (s *Store) Organization(_ context.Context, id string) (server.OrgSnapshot, error)

Organization reads a snapshot.

func (*Store) PutOffTimer

func (s *Store) PutOffTimer(_ context.Context, k server.TimerKey, try time.Time) error

PutOffTimer keeps a timer to be tried again later.

func (*Store) Record

func (s *Store) Record(_ context.Context, id string) (server.Record, error)

Record reads a record by its ID.

func (*Store) Records

func (s *Store) Records(_ context.Context, q server.RecordQuery) ([]server.Line, error)

Records reads a page of the record, the newest first.

func (*Store) Renew

func (s *Store) Renew(_ context.Context, b server.Begun) error

Renew keeps b in place of what was kept for its key.

func (*Store) RetryToDo

func (s *Store) RetryToDo(_ context.Context, id string, try time.Time, why string) error

RetryToDo gives one up to be tried again.

func (*Store) Save

func (s *Store) Save(ctx context.Context, m *server.Move) error

Save writes a move, all or nothing.

func (*Store) SaveChange

func (s *Store) SaveChange(_ context.Context, c *server.Change) error

SaveChange writes a change an administrator made, all or nothing (server.Change).

func (*Store) SaveOrganization

func (s *Store) SaveOrganization(_ context.Context, o server.OrgSnapshot) error

SaveOrganization keeps a snapshot and makes it the latest. A snapshot kept before (the same data) is given the new time.

func (*Store) Starts

func (s *Store) Starts(context.Context) ([]server.Start, error)

Starts reads the start of each version an administrator decided.

func (*Store) Ticket

func (s *Store) Ticket(_ context.Context, id string) (server.TicketRecord, error)

Ticket reads a ticket.

func (*Store) Tickets

Tickets reads the tickets of some versions of a kind, the newest first: by when they were made (the time of their first move), then by ID.

func (*Store) Timers

func (s *Store) Timers(_ context.Context, ticket string) ([]server.Timer, error)

Timers reads a ticket's timers.

func (*Store) ToDoItem

func (s *Store) ToDoItem(_ context.Context, id string) (server.ToDo, error)

ToDoItem reads one thing to do.

func (*Store) ToDoList

func (s *Store) ToDoList(_ context.Context, ticket string) ([]server.ToDo, error)

ToDoList reads a ticket's things to do.

func (*Store) Trial

func (s *Store) Trial(context.Context) (any, func(), error)

Trial answers a transaction that is never committed: what the books register with its AfterCommit is never done.

func (*Store) UploadOf

func (s *Store) UploadOf(_ context.Context, person, key string) (string, error)

UploadOf answers the upload a person made with a key that is not let go.

func (*Store) UploadsDeleted

func (s *Store) UploadsDeleted(_ context.Context, ids []string) error

UploadsDeleted records that the files of uploads let go are deleted.

func (*Store) Waiting

func (s *Store) Waiting(_ context.Context, people []string, q server.WaitingQuery) ([]server.TicketRecord, error)

Waiting reads the tickets that wait for any of the people, the newest first.

type Tx

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

Tx is what a move's Books is given: the books in memory register what they do with AfterCommit, and it is done only when the move is saved.

func (*Tx) AfterCommit

func (t *Tx) AfterCommit(f func())

AfterCommit registers f to be done once the move is saved.

Jump to

Keyboard shortcuts

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