Documentation
¶
Index ¶
- Variables
- type BaseEvent
- type Constraint
- type Definition
- func (d *Definition) AddEventListener(eventType EventType, listener EventListener)
- func (d *Definition) AddGuardEventListener(listener GuardEventListener)
- func (d *Definition) AllPlaces() []Place
- func (d *Definition) AllTransitions() []Transition
- func (d *Definition) Place(place Place) bool
- func (d *Definition) RemoveEventListener(eventType EventType, listener interface{})
- func (d *Definition) Transition(name string) *Transition
- type Event
- type EventListener
- type EventType
- type GuardEvent
- type GuardEventListener
- type GuardListener
- type Listener
- type Manager
- func (m *Manager) AddEventListener(eventType EventType, listener EventListener)
- func (m *Manager) AddGuardEventListener(listener GuardEventListener)
- func (m *Manager) CreateWorkflow(id string, definition *Definition, initialPlace Place) (*Workflow, error)
- func (m *Manager) DeleteWorkflow(id string) error
- func (m *Manager) GetWorkflow(id string, definition *Definition) (*Workflow, error)
- func (m *Manager) LoadWorkflow(id string, definition *Definition) (*Workflow, error)
- func (m *Manager) RemoveEventListener(eventType EventType, listener interface{})
- func (m *Manager) SaveWorkflow(id string, wf *Workflow) error
- type Marking
- type Place
- type Registry
- type Storage
- type Transition
- type Workflow
- func (w *Workflow) AddEventListener(eventType EventType, listener EventListener)
- func (w *Workflow) AddGuardEventListener(listener GuardEventListener)
- func (w *Workflow) Apply(targetPlaces []Place) error
- func (w *Workflow) ApplyWithContext(ctx context.Context, targetPlaces []Place) error
- func (w *Workflow) Can(to []Place) error
- func (w *Workflow) CanWithContext(ctx context.Context, to []Place) error
- func (w *Workflow) Context(key string) (interface{}, bool)
- func (w *Workflow) CurrentPlaces() []Place
- func (w *Workflow) Definition() *Definition
- func (w *Workflow) Diagram() string
- func (w *Workflow) EnabledTransitions() ([]Transition, error)
- func (w *Workflow) InitialPlace() Place
- func (w *Workflow) Marking() Marking
- func (w *Workflow) Name() string
- func (w *Workflow) RemoveEventListener(eventType EventType, listener interface{})
- func (w *Workflow) SetContext(key string, value interface{})
- func (w *Workflow) SetManager(m *Manager)
- func (w *Workflow) SetMarking(marking Marking) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrTransitionNotAllowed = fmt.Errorf("transition not allowed") ErrInvalidPlace = fmt.Errorf("invalid place") ErrInvalidTransition = fmt.Errorf("invalid transition") )
Common errors
Functions ¶
This section is empty.
Types ¶
type BaseEvent ¶
type BaseEvent struct {
// contains filtered or unexported fields
}
BaseEvent represents a workflow event
func NewEvent ¶
func NewEvent(ctx context.Context, eventType EventType, transition *Transition, from []Place, to []Place, workflow *Workflow) *BaseEvent
NewEvent creates a new BaseEvent instance
func (*BaseEvent) Transition ¶
func (e *BaseEvent) Transition() *Transition
Transition returns the transition associated with the event
type Constraint ¶
Constraint represents a validation constraint for a transition
type Definition ¶
type Definition struct {
Places []Place
Transitions []Transition
// Default listeners for this workflow type
Listeners map[EventType][]interface{}
}
Definition represents a workflow definition with places and transitions
func NewDefinition ¶
func NewDefinition(places []Place, transitions []Transition) (*Definition, error)
NewDefinition creates a new workflow definition
func (*Definition) AddEventListener ¶
func (d *Definition) AddEventListener(eventType EventType, listener EventListener)
AddEventListener adds a default event listener for a specific event type
func (*Definition) AddGuardEventListener ¶
func (d *Definition) AddGuardEventListener(listener GuardEventListener)
AddGuardEventListener adds a default guard event listener
func (*Definition) AllPlaces ¶
func (d *Definition) AllPlaces() []Place
AllPlaces returns all places (places) in the definition
func (*Definition) AllTransitions ¶
func (d *Definition) AllTransitions() []Transition
AllTransitions returns all transitions in the definition
func (*Definition) Place ¶
func (d *Definition) Place(place Place) bool
Place checks if a place exists in the definition
func (*Definition) RemoveEventListener ¶
func (d *Definition) RemoveEventListener(eventType EventType, listener interface{})
RemoveEventListener removes a default event listener
func (*Definition) Transition ¶
func (d *Definition) Transition(name string) *Transition
Transition returns a transition by name
type Event ¶
type Event interface {
Type() EventType
Transition() *Transition
From() []Place
To() []Place
Workflow() *Workflow
Context() context.Context
}
Event defines the common interface for all event types
type EventListener ¶
EventListener is a function that handles workflow events
type EventType ¶
type EventType string
EventType represents the type of workflow event
const ( // EventBeforeTransition is fired before a transition is applied EventBeforeTransition EventType = "before_transition" // EventAfterTransition is fired after a transition is applied EventAfterTransition EventType = "after_transition" // EventGuard is fired to check if a transition is allowed EventGuard EventType = "guard" )
type GuardEvent ¶
type GuardEvent struct {
BaseEvent
// contains filtered or unexported fields
}
GuardEvent represents a guard event in the workflow
func NewGuardEvent ¶
func NewGuardEvent(ctx context.Context, transition *Transition, from []Place, to []Place, workflow *Workflow) *GuardEvent
NewGuardEvent creates a new Guard Event instance
func (*GuardEvent) IsBlocking ¶
func (e *GuardEvent) IsBlocking() bool
IsBlocking returns whether the event is blocking
func (*GuardEvent) SetBlocking ¶
func (e *GuardEvent) SetBlocking(blocking bool)
SetBlocking sets whether the event is blocking
type GuardEventListener ¶
type GuardEventListener func(*GuardEvent) error
GuardEventListener is a function that handles guard events
type GuardListener ¶
type GuardListener interface {
HandleGuardEvent(*GuardEvent) error
}
GuardListener interface for handling guard events
type Manager ¶
type Manager struct {
// Dynamic listeners for all managed workflows
Listeners map[EventType][]interface{}
// contains filtered or unexported fields
}
Manager handles workflow instances and their persistence
func NewManager ¶
NewManager creates a new workflow manager
func (*Manager) AddEventListener ¶
func (m *Manager) AddEventListener(eventType EventType, listener EventListener)
AddEventListener adds a dynamic event listener for a specific event type
func (*Manager) AddGuardEventListener ¶
func (m *Manager) AddGuardEventListener(listener GuardEventListener)
AddGuardEventListener adds a dynamic guard event listener
func (*Manager) CreateWorkflow ¶
func (m *Manager) CreateWorkflow(id string, definition *Definition, initialPlace Place) (*Workflow, error)
CreateWorkflow creates a new workflow instance and saves it to storage
func (*Manager) DeleteWorkflow ¶
DeleteWorkflow removes a workflow instance and its state
func (*Manager) GetWorkflow ¶
func (m *Manager) GetWorkflow(id string, definition *Definition) (*Workflow, error)
GetWorkflow gets a workflow instance from the registry or loads it from storage
func (*Manager) LoadWorkflow ¶
func (m *Manager) LoadWorkflow(id string, definition *Definition) (*Workflow, error)
LoadWorkflow loads a workflow instance from storage
func (*Manager) RemoveEventListener ¶
RemoveEventListener removes a dynamic event listener
type Marking ¶
type Marking interface {
// Places returns the current places
Places() []Place
// SetPlaces sets the current places
SetPlaces(places []Place)
// HasPlace checks if a place exists
HasPlace(place Place) bool
// AddPlace adds a place
AddPlace(place Place) error
// RemovePlace removes a place
RemovePlace(place Place) error
}
Marking represents the current state of a workflow
func UnmarshalMarkingJSON ¶
UnmarshalMarkingJSON unmarshals JSON data into a Marking interface
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages multiple workflows
func (*Registry) AddWorkflow ¶
AddWorkflow adds a workflow to the registry
func (*Registry) HasWorkflow ¶
HasWorkflow checks if a workflow exists
func (*Registry) ListWorkflows ¶
ListWorkflows returns a list of all workflow names
func (*Registry) RemoveWorkflow ¶
RemoveWorkflow removes a workflow from the registry
type Storage ¶
type Storage interface {
// LoadState loads the workflow's places and its context data for the given ID.
LoadState(id string) (places []Place, context map[string]interface{}, err error)
// SaveState saves the workflow's places and its context data for the given ID.
SaveState(id string, places []Place, context map[string]interface{}) error
// DeleteState removes the workflow state for the given ID.
DeleteState(id string) error
}
Storage defines the interface for persisting workflow state. It is responsible for loading and saving the workflow's places (state) and its context data (custom fields).
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition represents a transition between places in the workflow
func MustNewTransition ¶
func MustNewTransition(name string, from []Place, to []Place) *Transition
MustNewTransition is a helper that creates a new transition and panics on error. This is useful for defining transitions in a declarative way.
func NewTransition ¶
func NewTransition(name string, from []Place, to []Place) (*Transition, error)
NewTransition creates a new transition
func (*Transition) AddConstraint ¶
func (t *Transition) AddConstraint(constraint Constraint)
AddConstraint adds a constraint to the transition
func (*Transition) From ¶
func (t *Transition) From() []Place
From returns the source places of the transition
func (*Transition) Metadata ¶
func (t *Transition) Metadata(key string) (interface{}, bool)
Metadata returns the value for the given key from the transition metadata
func (*Transition) SetMetadata ¶
func (t *Transition) SetMetadata(key string, value interface{})
SetMetadata sets metadata for the transition
func (*Transition) To ¶
func (t *Transition) To() []Place
To returns the target places of the transition
type Workflow ¶
type Workflow struct {
// contains filtered or unexported fields
}
Workflow represents a workflow instance
func NewWorkflow ¶
func NewWorkflow(name string, definition *Definition, initialPlace Place) (*Workflow, error)
NewWorkflow constructor
func (*Workflow) AddEventListener ¶
func (w *Workflow) AddEventListener(eventType EventType, listener EventListener)
AddEventListener adds an event listener for a specific event type
func (*Workflow) AddGuardEventListener ¶
func (w *Workflow) AddGuardEventListener(listener GuardEventListener)
AddGuardEventListener adds a guard event listener
func (*Workflow) ApplyWithContext ¶
ApplyWithContext applies a transition to the workflow with a context
func (*Workflow) CanWithContext ¶
CanWithContext checks if transition to target places is possible with a context
func (*Workflow) CurrentPlaces ¶
CurrentPlaces returns the current places of the workflow
func (*Workflow) Definition ¶
func (w *Workflow) Definition() *Definition
Definition returns the workflow definition
func (*Workflow) EnabledTransitions ¶
func (w *Workflow) EnabledTransitions() ([]Transition, error)
EnabledTransitions returns all transitions that can be applied in the current place
func (*Workflow) InitialPlace ¶
InitialPlace returns the initial place of the workflow
func (*Workflow) RemoveEventListener ¶
RemoveEventListener removes an event listener
func (*Workflow) SetContext ¶
SetContext sets a value in the workflow context
func (*Workflow) SetManager ¶
SetManager sets the manager pointer for this workflow
func (*Workflow) SetMarking ¶
SetMarking sets the workflow marking
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
document_approval
command
|
|
|
order_processing
command
|
|
|
simple_flow
command
|
|