Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateReferenceKey ¶
GenerateReferenceKey generate reference key used for change log
Types ¶
type Event ¶
type Event struct { Name string // contains filtered or unexported fields }
Event contains Event information, including transition hooks
func (*Event) To ¶
func (event *Event) To(name string) *EventTransition
To define EventTransition of go to a state
type EventTransition ¶
type EventTransition struct {
// contains filtered or unexported fields
}
EventTransition hold event's to/froms states, also including befores, afters hooks
func (*EventTransition) After ¶
func (transition *EventTransition) After(fc func(value interface{}, tx *gorm.DB) error) *EventTransition
After register after hooks
func (*EventTransition) Before ¶
func (transition *EventTransition) Before(fc func(value interface{}, tx *gorm.DB) error) *EventTransition
Before register before hooks
func (*EventTransition) From ¶
func (transition *EventTransition) From(states ...string) *EventTransition
From used to define from states
type State ¶
type State struct { Name string // contains filtered or unexported fields }
State contains State information, including enter, exit hooks
type StateChangeLog ¶
type StateChangeLog struct { gorm.Model ReferTable string ReferID string From string To string Note string `sql:"size:1024"` audited.AuditedModel }
StateChangeLog a model that used to keep state change logs
func GetLastStateChange ¶
func GetLastStateChange(model interface{}, db *gorm.DB) *StateChangeLog
GetLastStateChange gets last state change
func GetStateChangeLogs ¶
func GetStateChangeLogs(model interface{}, db *gorm.DB) []StateChangeLog
GetStateChangeLogs get state change logs
func (*StateChangeLog) ConfigureQorResource ¶
func (stageChangeLog *StateChangeLog) ConfigureQorResource(res resource.Resourcer)
ConfigureQorResource used to configure transition for qor admin
type StateMachine ¶
type StateMachine struct {
// contains filtered or unexported fields
}
StateMachine a struct that hold states, events definitions
func New ¶
func New(value interface{}) *StateMachine
New initialize a new StateMachine that hold states, events definitions
func (*StateMachine) Event ¶
func (sm *StateMachine) Event(name string) *Event
Event define an event
func (*StateMachine) Initial ¶
func (sm *StateMachine) Initial(name string) *StateMachine
Initial define the initial state
type Transition ¶
type Transition struct { State string StateChangeLogs []StateChangeLog `sql:"-"` }
Transition is a struct, embed it in your struct to enable state machine for the struct
func (*Transition) ConfigureQorResource ¶
func (transition *Transition) ConfigureQorResource(res resource.Resourcer)
ConfigureQorResource used to configure transition for qor admin
func (Transition) GetState ¶
func (transition Transition) GetState() string
GetState get current state from
func (*Transition) SetState ¶
func (transition *Transition) SetState(name string)
SetState set state to Stater, just set, won't save it into database