# README
go-statemachine
参考了alibaba/COLA/cola-component-statemachine 的实现
Install
go get github.com/GoCarnival/go-statemachine
Usage
package main
import (
"github.com/GoCarnival/go-statemachine"
"fmt"
)
func main() {
builder := statemachine.Builder[string, string, any]{}
builder.ExternalTransition().From("foo").To("bar").On("ping").When(func(ctx *any) bool {
return true
}).Perform(func(from string, to string, event string, context *any) {
fmt.Println("do something")
})
var fetcher statemachine.CurrentStateFetcher[string, any] = func(ctx *any) string {
return "foo"
}
builder.SetCurrentStateFetcher(fetcher)
s := builder.Build("test")
target := s.FireEvent("foo", "ping", nil)
fmt.Println(target)
s.Verify("foo", "ping")
s.FireEventByFetcher("ping", nil)
s.VerifyWithFetcher("ping", nil)
}
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StateMachine the state machine.
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
Action 是状态机规则命中后,执行的业务逻辑.
Condition 是状态机路由后在执行 Action 之前的前置校验,在配置状态机时可以为空.
No description provided by the author
TransitionType TransitionType 状态转移类型 当前只有 EXTERNAL 与 INTERNAL 两种.