itimofeev/go-saga ? reverse-engineered prompt

Reverse engineered prompt

Build me a small Go library for the saga pattern that helps coordinate a multi step workflow across services.

I want to define a saga with named steps, where each step has a normal function and a compensation function that can undo it if something fails later. If any step returns an error, the library should automatically run the compensation functions for the steps that already succeeded, in reverse order, so the whole operation is rolled back.

Please include a simple coordinator that can execute the saga and keep track of what happened, plus a basic in memory store for logs so it works without needing a database. I’d also like a clear example showing how to use it in a test, and a few tests that prove rollback works when a later step fails.

Keep the API easy to use and close to a typical Go style. If you need to check anything, look up current docs online first.

Are you gonna build this?

make sure you review the code using coderabbit

Try freeSponsored — opens CodeRabbit in a new tab