fsmgo is a clean, modular, and reusable Go library for building finite state machines, inspired by FSMgasm but adapted with Go idioms for concurrent and complex systems.
go get github.com/josscoder/fsmgo
Then import:
import "github.com/josscoder/fsmgo/state"
A fsmgo state has a clear lifecycle:
OnStart()
– called when the state begins.OnUpdate()
– called every tick or cycle.OnEnd()
– called when the state ends.
Optional pause lifecycle:
OnPause()
OnResume()
States can implement these by using the optional PauseAware
interface:
type PauseAware interface {
OnPause()
OnResume()
}
States can define a duration (time.Duration
) or custom conditions to determine when they complete.
See practical examples in the example folder.
fsmgo is licensed under the MIT License. Feel free to use, modify, and distribute it in your projects.