https://github.com/austingebauer/go-fsm
A Go library that can be used to construct finite-state machines.
https://github.com/austingebauer/go-fsm
Last synced: 10 months ago
JSON representation
A Go library that can be used to construct finite-state machines.
- Host: GitHub
- URL: https://github.com/austingebauer/go-fsm
- Owner: austingebauer
- License: mit
- Created: 2019-04-24T20:15:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-02T07:14:52.000Z (about 6 years ago)
- Last Synced: 2025-02-08T20:23:55.521Z (12 months ago)
- Language: Go
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-fsm [](https://goreportcard.com/report/github.com/austingebauer/go-fsm) [](https://godoc.org/github.com/austingebauer/go-fsm)
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](https://github.com/golang/go/blob/master/src/text/template/parse/lex.go#L105).
## Installation
To install `go-fsm`, use `go get`.
```bash
go get github.com/austingebauer/go-fsm
```
Then import the library into your Go program.
```go
import "github.com/austingebauer/go-fsm"
```
## Usage
See example usage in [example/main.go](./example/main.go), which uses go-fsm to write a
finite-state machine for the [pacman ghosts state machine](https://bits.theorem.co/images/posts/2015-01-21-state-design-pacman-fsm.png).
To run the example:
```bash
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:
```bash
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:

## 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](LICENSE)