Achieve this repo, move it into github.com/iTellis/common
Finite-state machine in go
go get -u github.com/iTrellis/common/fsm
// FSMRepo the functions of fsm interface
type FSMRepo interface {
// add a transction into cache
Add(*Transaction)
// remove all transactions
Remove()
// remove namespace's transactions
RemoveNamespace(namespace string)
// remove a transaction by information
RemoveByTransaction(*Transaction)
// get target transaction by current information
GetTargetTranstion(namespace, curStatus, event string) *Transaction
}
f := fsm.New()
f.Add(&fsm.Transaction{
Namespace: "namespace",
CurrentStatus: "status1",
Event: "event1",
TargetStatus: "status2",
})
fmt.Println(f.GetTargetTranstion("namespace", "status1", "event1"))
f.Remove()
fmt.Println(f.GetTargetTranstion("namespace", "status1", "event1"))