/go-fsm

A Go library that can be used to construct finite-state machines.

Primary LanguageGoMIT LicenseMIT

go-fsm GoReportCard GoDoc

A golang library that can be used to construct finite-state machines.

A finite-state machine is an abstract machine that can be in exactly one of a finite number of states at any given time.

The API and design of this library is inspired by the finite-state machine implementation in the golang template lexer.

Installation

To install go-fsm, use go get.

go get github.com/austingebauer/go-fsm

Then import the library into your Go program.

import "github.com/austingebauer/go-fsm"

Usage

See example usage in example/main.go, which uses go-fsm to write a finite-state machine for the pacman ghosts state machine.

To run the example:

go run example/main.go

Generating a State Diagram

To generate a state diagram showing the states, transitions, and steps of the finite-state machine execution:

dot example/dot_graph.gv -T png > example/dot_graph.png && open example/dot_graph.png

An example image generated from running the example finite-state machine:

go-fsm finite-state-machine

Contributing

Pull requests are welcome.

For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests along with changes.

License

MIT