Documentation ¶
Overview ¶
Package statemanager stores the global state and provides mechanisms for updating the state, listing for state updates, registering commands, and triggering commands
Index ¶
- Variables
- func BaseFilePath() string
- func Command(name string, data []string) error
- func Initialize()
- func Lock()
- func ParseIDs(k string) []string
- func RegisterCommand(name string, c CommandFunc)
- func RegisterPatternUpdaterBool(name string, groupPriority uint8, u UpdaterPatternBoolFunc)
- func RegisterPatternUpdaterInt64(name string, groupPriority uint8, u UpdaterPatternInt64Func)
- func RegisterPatternUpdaterString(name string, groupPriority uint8, u UpdaterPatternStringFunc)
- func RegisterPatternUpdaterTime(name string, groupPriority uint8, u UpdaterPatternTimeFunc)
- func RegisterUpdaterBool(name string, groupPriority uint8, u UpdaterBoolFunc)
- func RegisterUpdaterInt64(name string, groupPriority uint8, u UpdaterInt64Func)
- func RegisterUpdaterString(name string, groupPriority uint8, u UpdaterStringFunc)
- func RegisterUpdaterTime(name string, groupPriority uint8, u UpdaterTimeFunc)
- func SetBaseFilePath(p ...string)
- func SetDebug(d bool)
- func StateDelete(k string) error
- func StateSet(keyName string, value string) error
- func StateSetGroup(values map[string]string)
- func StateUpdateBool(k string, v bool) error
- func StateUpdateInt64(k string, v int64) error
- func StateUpdateString(k string, v string) error
- func StateUpdateTime(k string, v time.Time) error
- func Unlock()
- func UnregisterCommand(name string)
- func UnregisterUpdater(name string)
- type CommandFunc
- type Listener
- type Saver
- type UpdaterBoolFunc
- type UpdaterInt64Func
- type UpdaterPatternBoolFunc
- type UpdaterPatternInt64Func
- type UpdaterPatternStringFunc
- type UpdaterPatternTimeFunc
- type UpdaterStringFunc
- type UpdaterTimeFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("State Not Found")
ErrNotFound is returned when the key name is not in the current state
var ErrUnknownType = errors.New("Unknown State Type")
ErrUnknownType is returned when the type passed to the statemanager is not one of the supported types (currently string, int64, bool)
var ErrUpdaterNotFound = errors.New("Updater Not Found")
ErrUpdaterNotFound is returned when an updater cannot be located for the key name
Functions ¶
func BaseFilePath ¶
func BaseFilePath() string
BaseFilePath returns the base directory for loading or saving files
func Command ¶
Command requests the command registered with name be called and passed data as parameters. Returns nil error on success, errCommandNotFound, errCommandArguments, or an error from the registered command function
func Lock ¶
func Lock()
Lock places the statemanager in a locked state, should be called before any updates to the state are made, but only once.
func ParseIDs ¶
ParseIDs returns all values within () in the input string. Example Scoreboard.Team(1).Skater(abc123).Name returns ["1", "abc123"]
func RegisterCommand ¶
func RegisterCommand(name string, c CommandFunc)
RegisterCommand registers the CommandFunc with the command subsystem with name
func RegisterPatternUpdaterBool ¶
func RegisterPatternUpdaterBool(name string, groupPriority uint8, u UpdaterPatternBoolFunc)
RegisterPatternUpdaterBool adds a bool updater to the statemanager.
func RegisterPatternUpdaterInt64 ¶
func RegisterPatternUpdaterInt64(name string, groupPriority uint8, u UpdaterPatternInt64Func)
RegisterPatternUpdaterInt64 adds an int64 updater to the statemanager.
func RegisterPatternUpdaterString ¶
func RegisterPatternUpdaterString(name string, groupPriority uint8, u UpdaterPatternStringFunc)
RegisterPatternUpdaterString adds a string updater to the statemanager.
func RegisterPatternUpdaterTime ¶
func RegisterPatternUpdaterTime(name string, groupPriority uint8, u UpdaterPatternTimeFunc)
RegisterPatternUpdaterTime adds a time updater to the statemanager.
func RegisterUpdaterBool ¶
func RegisterUpdaterBool(name string, groupPriority uint8, u UpdaterBoolFunc)
RegisterUpdaterBool adds a bool updater to the statemanager.
func RegisterUpdaterInt64 ¶
func RegisterUpdaterInt64(name string, groupPriority uint8, u UpdaterInt64Func)
RegisterUpdaterInt64 adds an int64 updater to the statemanager.
func RegisterUpdaterString ¶
func RegisterUpdaterString(name string, groupPriority uint8, u UpdaterStringFunc)
RegisterUpdaterString adds a string updater to the statemanager.
func RegisterUpdaterTime ¶
func RegisterUpdaterTime(name string, groupPriority uint8, u UpdaterTimeFunc)
RegisterUpdaterTime adds a time updater to the statemanager.
func SetBaseFilePath ¶
func SetBaseFilePath(p ...string)
SetBaseFilePath sets the base directory for loading or saving files
func StateDelete ¶
func StateSet ¶
StateSet attempts to update the state to value using keyName to lookup a handler. It returns an error on failure.
func StateSetGroup ¶
StateSetGroup attempts to update the state using a map of key/values to lookup handlers. Calls StateSet for each key/values using the groupPriority of the registered updater to call lower numbers (higher priority) first. Allows setting things like min/max values before the actual number.
func StateUpdateBool ¶
func StateUpdateInt64 ¶
func StateUpdateString ¶
func Unlock ¶
func Unlock()
Unlock removes the lock from the statemanager and starts the processing of any updates to listeners waiting for changes
func UnregisterCommand ¶
func UnregisterCommand(name string)
UnregisterCommand removes the CommandFunc registered with name from the command subsystem
func UnregisterUpdater ¶
func UnregisterUpdater(name string)
UnregisterUpdater removes an updater from the statemanager.
Types ¶
type CommandFunc ¶
CommandFunc is a callback function when a command is triggered. Commands can be registered by RegisterCommand and unregistered by UnregisterCommand
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener allows functions to listen for changes in the state of the scoreboard
func NewListener ¶
NewListener creates a listener with name describing the listener (for log messages) and cb is a callback function which gets called on changes to the state filtered by Listener.RegisterPaths
func (*Listener) Close ¶
func (l *Listener) Close()
Close closes the listener. After this call it the callback will never be called for this listener again.
func (*Listener) RegisterPaths ¶
RegisterPaths adds the paths to the listener to get updates. See PatternMatch for examples of how the pattern matching is done. The callback will immediately be called with and matching paths before returning to the caller.
func (*Listener) UnregisterPaths ¶
UnregisterPaths removes the paths from the listener.
type Saver ¶
Saver handles saving part (or all) of the state to a file
func NewSaver ¶
NewSaver creates a new saver. name: name of the file base: pattern to match (see PatternMatch for examples of matching) interval: time between saves. Zero if you want/need a save on every change, will only
save if something has actually changed
version: save older versions of the file (move file to file.1, file.1 to file.2, etc) NOT IMPLEMENTED!
type UpdaterBoolFunc ¶
UpdaterBoolFunc is a callback type for bool updates from the state engine
type UpdaterInt64Func ¶
UpdaterInt64Func is a callback type for int64 updates from the state engine
type UpdaterPatternBoolFunc ¶
UpdaterPatternBoolFunc is a callback type for bool updates from the state engine
type UpdaterPatternInt64Func ¶
UpdaterPatternInt64Func is a callback type for int64 updates from the state engine
type UpdaterPatternStringFunc ¶
UpdaterPatternStringFunc is a callback type for string updates from the state engine
type UpdaterPatternTimeFunc ¶
UpdaterPatternTimeFunc is a callback type for time updates from the state engine
type UpdaterStringFunc ¶
UpdaterStringFunc is a callback type for string updates from the state engine
type UpdaterTimeFunc ¶
UpdaterTimeFunc is a callback type for time updates from the state engine