storage

package
v0.0.0-...-01bad0f Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package storage provides storage for the cachable token interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("token not found")
	ErrStorageFailure = errors.New("storage failure")
)

Err* are sentinel errors.

Functions

func WithBytes

func WithBytes(b []byte) func(t *Test)

WithBytes sets the initial state of the storage.

func WithReadError

func WithReadError(in func(*Test) error) func(t *Test)

WithReadError sets the error for the read function to return.

func WithWriteError

func WithWriteError(in func(*Test, []byte) error) func(t *Test)

WithWriteError sets the error for the write function to return

Types

type File

type File struct {
	Path string
}

File provides simple file-backed storage for the token interface.

func (*File) Read

func (f *File) Read() ([]byte, error)

Read implements storage.Read

func (*File) Write

func (f *File) Write(bytes []byte) error

Write implements storage.Write. It uses a swap file and rename operation to ensure the change is atomic.

type Storage

type Storage interface {
	Read() ([]byte, error)
	Write([]byte) error
}

Storage is the interface that stores and retrieves bytes from disk. It is ... similar to the io.ReadWriter, except the Read/Write methods make assumptions that the underlying data should be truncated before new data is written in, and that users always want the full set of bytes.

type Test

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

Test storage is just storage that is useful to make assertions in tests. Do not use it in production; there are better tools for everything you could possibly do with this.

func NewTest

func NewTest(f ...func(t *Test)) *Test

NewTest generates a new test storage

func (*Test) Read

func (t *Test) Read() ([]byte, error)

Read implements storage.Read

func (*Test) Write

func (t *Test) Write(input []byte) error

Write implements storage.Write

Jump to

Keyboard shortcuts

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