finds.dev← search

// the find

looplab/fsm

★ 3,385 · Go · Apache-2.0 · updated May 2025

Finite State Machine for Go

A finite state machine library for Go, letting you define states, events, and callbacks in a declarative style. Mature enough (10+ years old based on lineage) to be boring in the good sense — no surprises. Good fit for workflow engines, connection lifecycle managers, or anywhere you're manually tracking state transitions with a pile of if/else.

Callback system is flexible — you can hook into enter_state, leave_state, before_event, after_event, or specific named variants of each, which covers most real transition logic without fighting the API. Built-in Graphviz and Mermaid visualizer exports are genuinely useful for documenting complex machines. Context propagation through Event() means you can cancel async transitions cleanly. The 'uncancel context' helper is a thoughtful detail — lets callbacks run even when the triggering context is cancelled.

No generics — the FSM is stringly typed; state and event names are plain strings with no compile-time safety. Typos in state names are runtime errors, not build errors. No support for hierarchical (nested) states, so anything with substates means you either flatten everything into one machine or compose multiple FSMs yourself. Concurrency story is weak — the struct is not goroutine-safe and the docs are vague about how to handle concurrent events. No persistence or serialization support, so if you need to rehydrate an FSM from a database, you're on your own.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →