Documentation ¶
Index ¶
- Variables
- func Copy(ctx context.Context, dest Store, src Store) error
- type MockStore
- func (_m *MockStore) Close() error
- func (_m *MockStore) DeleteAttachment(ctx context.Context, id int64) error
- func (_m *MockStore) GetAttachment(ctx context.Context, id int64) ([]byte, error)
- func (_m *MockStore) ListAttachments(ctx context.Context) ([]int64, error)
- func (_m *MockStore) SetAttachment(ctx context.Context, id int64, blob []byte) error
- type Store
Constants ¶
This section is empty.
Variables ¶
var NewTempStore = func() (Store, error) { db, delete, err := sqlite.CreateTemp() if err != nil { return nil, errors.Wrap(err, "unable to make temporary attachment store") } store, err := NewSQLStore(db) return &tempStore{ store: store, close: func() error { delete() return nil }, }, err }
NewTempStore creates a Store in a temporary file, and when you Close the store, it deletes that file. It's a variable so it can be overwritten if you import this package. The built-in implementation uses SQLite, but any other implementation will work so long as its Close method removes all traces of this store
Functions ¶
Types ¶
type MockStore ¶
MockStore is an autogenerated mock type for the Store type
func NewMockStore ¶
func NewMockStore(t mockConstructorTestingTNewMockStore) *MockStore
NewMockStore creates a new instance of MockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func (*MockStore) DeleteAttachment ¶
DeleteAttachment provides a mock function with given fields: ctx, id
func (*MockStore) GetAttachment ¶
GetAttachment provides a mock function with given fields: ctx, id
func (*MockStore) ListAttachments ¶
ListAttachments provides a mock function with given fields: ctx
type Store ¶
type Store interface { // SetAttachment saves an attachment, so that later on GetAttachment can retrieve it. SetAttachment(ctx context.Context, id int64, blob []byte) error // GetAttachment retrieves an attachment previously stored by SetAttachment. If the ID was never used with SetAttachment, or was deleted with DeleteAttachment, it returns an error. GetAttachment(ctx context.Context, id int64) (blob []byte, err error) // ListAttachments gives a list of attachment IDs that have been set and haven't been deleted. ListAttachments(ctx context.Context) (ids []int64, err error) // DeleteAttachment frees up resources used to store an attachment, and causes GetAttachment to error going forward when asked for the deleted attachment. DeleteAttachment(ctx context.Context, id int64) (err error) // Close allows for cleaning up Close() (err error) }
Store is a way to store and retrieve binary blobs by IDs.
func Discard ¶
func Discard() Store
Discard never actually sets or deletes attachments. Never able to get attachments either.
func NewSQLStore ¶
NewSQLStore makes a Store that uses an SQL database to store attachments. You can supply either a *sql.DB or a *sql.Tx for the queries to run under.