Documentation ¶
Overview ¶
Package io contains the definition of the IO Provider, as well as various implementations of the concept.
Index ¶
- Variables
- type Bolt
- func (b *Bolt) Delete(_ context.Context, id []byte, dataType DataType) error
- func (b *Bolt) Get(_ context.Context, id []byte, dataType DataType) ([]byte, error)
- func (b *Bolt) Put(_ context.Context, id []byte, dataType DataType, data []byte) error
- func (b *Bolt) Update(_ context.Context, id []byte, dataType DataType, data []byte) error
- type DataType
- type Mem
- func (m *Mem) Delete(_ context.Context, id []byte, dataType DataType) error
- func (m *Mem) Get(_ context.Context, id []byte, dataType DataType) ([]byte, error)
- func (m *Mem) Put(_ context.Context, id []byte, dataType DataType, data []byte) error
- func (m *Mem) Update(_ context.Context, id []byte, dataType DataType, data []byte) error
- type Provider
- type Proxy
- func (o *Proxy) Delete(ctx context.Context, id []byte, dataType DataType) error
- func (o *Proxy) Get(ctx context.Context, id []byte, dataType DataType) ([]byte, error)
- func (o *Proxy) Put(ctx context.Context, id []byte, dataType DataType, data []byte) error
- func (o *Proxy) Update(ctx context.Context, id []byte, dataType DataType, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("already exists")
Error returned if data is found during a "Put" call.
var ErrNotFound = errors.New("not found")
Error returned if data is not found during a "Get" or "Update" call.
Functions ¶
This section is empty.
Types ¶
type Bolt ¶
type Bolt struct {
// contains filtered or unexported fields
}
Mem implements an IO Provider backed by the key/value database bolt..
type DataType ¶
type DataType uint16
Types of data supported by an IO Provider.
type Mem ¶
type Mem struct {
// contains filtered or unexported fields
}
Mem implements an in-memory version of an IO Provider.
type Provider ¶
type Provider interface { // Put sends bytes to the IO Provider. The data is identified by an ID and a data type. // Should return ErrAlreadyExists if the data already exists in the IO Provider. Put(ctx context.Context, id []byte, dataType DataType, data []byte) error // Get fetches data from the IO Provider. The data is identified by an ID and a data type. // Should return ErrNotFound if the data does not exist in the IO Provider. Get(ctx context.Context, id []byte, dataType DataType) ([]byte, error) // Update is similar to Put but updates data previously sent to the IO Provider. // Should return ErrNotFound if the data does not exist in the IO Provider. Update(ctx context.Context, id []byte, dataType DataType, data []byte) error // Delete removes data previously sent to the IO Provider. // Should not error if the data does not exist in the IO Provider. Delete(ctx context.Context, id []byte, dataType DataType) error }
Provider is the interface an IO Provider must implement to handle data from D1.
type Proxy ¶
type Proxy struct { Implementation Provider PutFunc func(ctx context.Context, id []byte, dataType DataType, data []byte) error GetFunc func(ctx context.Context, id []byte, dataType DataType) ([]byte, error) UpdateFunc func(ctx context.Context, id []byte, dataType DataType, data []byte) error DeleteFunc func(ctx context.Context, id []byte, dataType DataType) error }
Proxy is an IO Provider that wraps other IO Providers By default, it forwards calls directly to the implementation, but allows you to customize the behavior as you see fit by changing the individual functions as you see fit.
func NewProxy ¶
NewProxy returns a basic implementation of Proxy that can be used as a basis for tests.