Documentation ¶
Index ¶
- Constants
- Variables
- func CfgHasState(configuration *protos.Configuration, state string) bool
- func CheckValid(c *protos.Configuration) error
- func GetVersionId(c *protos.Configuration) string
- func HasState(transition *protos.Transition, state string) bool
- func NewEvent(eventName string) *protos.Event
- func UpdateEvent(event *protos.Event)
- type ConfiguredStateMachine
Constants ¶
const (
ConfigurationVersionSeparator = ":"
)
Variables ¶
var ( Release string MalformedConfigurationError = fmt.Errorf("this configuration cannot be parsed") MissingNameConfigurationError = fmt.Errorf( "configuration must always specify a name (and optionally a version)") MissingStatesConfigurationError = fmt.Errorf( "configuration must always specify at least one state") MissingDestinationError = fmt.Errorf( "event must always have a `Destination` statemachine") MissingEventNameError = fmt.Errorf( "events must always specify the event type") MismatchStartingStateConfigurationError = fmt.Errorf( "the StartingState must be one of the possible FSM states") EmptyStartingStateConfigurationError = fmt.Errorf("the StartingState must be non-empty") UnexpectedTransitionError = fmt.Errorf("unexpected event transition") UnexpectedError = fmt.Errorf("the request was malformed") UnreachableStateConfigurationError = "state %s is not used in any of the transitions" // Logger is made accessible so that its `Level` can be changed // or can be sent to a `NullLog` during testing. Logger = log.NewLog("api") )
Functions ¶
func CfgHasState ¶
func CfgHasState(configuration *protos.Configuration, state string) bool
CfgHasState checks that `state` is one of the Configuration's `States`
func CheckValid ¶
func CheckValid(c *protos.Configuration) error
CheckValid will validate that there is at least one state, and that the starting state is one of the possible states; further for any of the states it will check that they appear in at least one transition.
Finally, it will check that the name is valid, and that the generated `ConfigId` is a valid URI segment.
func GetVersionId ¶
func GetVersionId(c *protos.Configuration) string
func HasState ¶
func HasState(transition *protos.Transition, state string) bool
HasState will check whether a given state is either origin or destination for the Transition
func UpdateEvent ¶
UpdateEvent adds the ID and timestamp to the event, if not already set.
Types ¶
type ConfiguredStateMachine ¶
type ConfiguredStateMachine struct { Config *protos.Configuration FSM *protos.FiniteStateMachine }
ConfiguredStateMachine is the internal representation of an FSM, which carries within itself the configuration for ease of use.
func NewStateMachine ¶
func NewStateMachine(configuration *protos.Configuration) (*ConfiguredStateMachine, error)
func (*ConfiguredStateMachine) CheckValid ¶
func (x *ConfiguredStateMachine) CheckValid() bool
CheckValid checks that the Configuration is valid and that the current FSM `state` is one of the allowed states in the Configuration.
We also check that the reported FSM ConfigId, matches the Configuration's name, version.
func (*ConfiguredStateMachine) Reset ¶
func (x *ConfiguredStateMachine) Reset()