Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neonxp/workflow
Simple state machine for go
https://github.com/neonxp/workflow
Last synced: about 1 month ago
JSON representation
Simple state machine for go
- Host: GitHub
- URL: https://github.com/neonxp/workflow
- Owner: neonxp
- Created: 2019-12-08T10:39:23.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-15T13:08:31.000Z (over 4 years ago)
- Last Synced: 2024-06-20T01:50:36.897Z (7 months ago)
- Language: Go
- Size: 45.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Workflow for Go
[![GoDoc](https://godoc.org/github.com/neonxp/workflow?status.svg)](https://godoc.org/github.com/neonxp/workflow)
Simple state machine. Inspired by [Symfony Workflow](https://github.com/symfony/workflow).
## Example usage
```go
o := new(ObjectImplementedPlaceer)w := NewWorkflow("Start")
w.AddTransition("Start", "A")
w.AddTransition("Start", "B")
w.AddTransition("A", "C")
w.AddTransition("B", "D")
w.AddTransition( "C", "D")
w.AddTransition("C", "Finish")
w.AddTransition("D", "Finish")w.Can(o, "A") // == nil
w.Can(o, "C") // == ErrTransitionNotFoundw.GetEnabledTransitions(o) // []Place{"A", "B"}
w.Apply(o, "A") // o now at "A" place
w.GetEnabledTransitions(o) // []Place{"C"}w.DumpToDot() // See above
```## Dump result
```
digraph {
Start[color="blue"]
Start -> A[label="Start → A"];
Start -> B[label="Start → B"];
A -> C[label="A → C"];
B -> D[label="B → D"];
C -> D[label="C → D"];
C -> Finish[label="C → Finish"];
D -> Finish[label="D → Finish"];
}
```Visualization:
![Workflow visualization](images/example.png)