Documentation ¶
Overview ¶
Package statemanager implements simple constructs for saving and restoring state from disk. It provides the interface for a StateManager which can read/write arbitrary json data from/to disk.
Index ¶
Constants ¶
const (
ECSDataVersion = 31
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoopStateManager ¶
type NoopStateManager struct{}
NoopStateManager is a state manager that succeeds for all reads/writes without even trying; it allows disabling of state serialization by being a drop-in replacement so no other code need be concerned with it.
func (*NoopStateManager) ForceSave ¶
func (nsm *NoopStateManager) ForceSave() error
ForceSave does nothing, successfully
func (*NoopStateManager) Load ¶
func (nsm *NoopStateManager) Load() error
Load does nothing, successfully
func (*NoopStateManager) Save ¶
func (nsm *NoopStateManager) Save() error
Save does nothing, successfully
type Option ¶
type Option func(StateManager)
Option functions are functions that may be used as part of constructing a new StateManager
func AddSaveable ¶
AddSaveable is an option that adds a given saveable as one that should be saved under the given name. The name must be the same across uses of the statemanager (e.g. program invocations) for it to be serialized and deserialized correctly.
type Saveable ¶
type Saveable interface{}
Saveable types should be able to be json serializable and deserializable Properly, this should have json.Marshaler/json.Unmarshaler here, but string and so on can be marshaled/unmarshaled sanely but don't fit those interfaces.
type StateManager ¶
A StateManager can load and save state from disk. Load is not expected to return an error if there is no state to load.
func NewNoopStateManager ¶
func NewNoopStateManager() StateManager
NewNoopStateManager constructs a state manager
func NewStateManager ¶
func NewStateManager(cfg *config.Config, options ...Option) (StateManager, error)
NewStateManager constructs a new StateManager which saves data at the location specified in cfg and operates under the given options. The returned StateManager will not save more often than every 10 seconds and will not reliably return errors with Save, but will log them appropriately.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mock_statemanager is a generated GoMock package.
|
Package mock_statemanager is a generated GoMock package. |