{"id":37154831,"url":"https://github.com/things-go/fsm","last_synced_at":"2026-01-14T18:18:43.521Z","repository":{"id":56854638,"uuid":"523991093","full_name":"things-go/fsm","owner":"things-go","description":"Finite State Machine","archived":false,"fork":false,"pushed_at":"2024-05-08T05:38:28.000Z","size":99,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-20T08:14:49.056Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/things-go.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-12T07:13:37.000Z","updated_at":"2024-05-08T05:38:24.000Z","dependencies_parsed_at":"2024-04-25T23:27:16.161Z","dependency_job_id":"0ec3f8f9-822b-4ec2-85f0-1c53f4649668","html_url":"https://github.com/things-go/fsm","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/things-go/fsm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Ffsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Ffsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Ffsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Ffsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/things-go","download_url":"https://codeload.github.com/things-go/fsm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/things-go%2Ffsm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28430315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T18:18:42.965Z","updated_at":"2026-01-14T18:18:43.502Z","avatar_url":"https://github.com/things-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fsm\n\nFinite State Machine \n\n[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go\u0026logoColor=white)](https://pkg.go.dev/github.com/things-go/fsm?tab=doc)\n[![codecov](https://codecov.io/gh/things-go/fsm/branch/main/graph/badge.svg)](https://codecov.io/gh/things-go/fsm)\n[![Tests](https://github.com/things-go/fsm/actions/workflows/ci.yml/badge.svg)](https://github.com/things-go/fsm/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/things-go/fsm)](https://goreportcard.com/report/github.com/things-go/fsm)\n[![Licence](https://img.shields.io/github/license/things-go/fsm)](https://raw.githubusercontent.com/things-go/fsm/main/LICENSE)\n[![Tag](https://img.shields.io/github/v/tag/things-go/fsm)](https://github.com/things-go/fsm/tags)\n\n\n## Features\n\n## Usage\n\n### Installation\n\nUse go get.\n```bash\n    go get github.com/things-go/fsm\n```\n\nThen import the package into your own code.\n```bash\n    import \"github.com/things-go/fsm\"\n```\n\n### Example\n\n[embedmd]:# (examples/generic.go go)\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/things-go/fsm\"\n)\n\ntype MyEvent int\n\nconst (\n\tClose MyEvent = 1\n\tOpen  MyEvent = 2\n)\n\nfunc (c MyEvent) String() string {\n\tswitch c {\n\tcase 1:\n\t\treturn \"close\"\n\tcase 2:\n\t\treturn \"open\"\n\tdefault:\n\t\treturn \"none\"\n\t}\n}\n\ntype MyState int\n\nfunc (c MyState) String() string {\n\tswitch c {\n\tcase 1:\n\t\treturn \"closed\"\n\tcase 2:\n\t\treturn \"opened\"\n\tdefault:\n\t\treturn \"none\"\n\t}\n}\n\nconst (\n\tIsClosed MyState = 1\n\tIsOpen   MyState = 2\n)\n\nfunc main() {\n\tf := fsm.NewSafeFsm[MyEvent, MyState](\n\t\tIsClosed,\n\t\tfsm.NewTransition([]fsm.Transform[MyEvent, MyState]{\n\t\t\t{Event: Open, Src: []MyState{IsClosed}, Dst: IsOpen},\n\t\t\t{Event: Close, Src: []MyState{IsOpen}, Dst: IsClosed},\n\t\t}),\n\t)\n\tfmt.Println(f.Current())\n\terr := f.Trigger(Open)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(f.Current())\n\terr = f.Trigger(Close)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(f.Current())\n\t// Output:\n\t// closed\n\t// opened\n\t// closed\n\tfmt.Println(fsm.VisualizeGraphviz[MyEvent, MyState](f))\n\t// digraph fsm {\n\t//    \"closed\" -\u003e \"opened\" [ label = \"open\" ];\n\t//    \"opened\" -\u003e \"closed\" [ label = \"close\" ];\n\t//\n\t//    \"closed\";\n\t//    \"opened\";\n\t// }\n}\n```\n\n## License\n\nThis project is under MIT License. See the [LICENSE](LICENSE) file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthings-go%2Ffsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthings-go%2Ffsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthings-go%2Ffsm/lists"}