https://github.com/go-utils/transactions
Simply transactions
https://github.com/go-utils/transactions
go golang transaction
Last synced: 8 months ago
JSON representation
Simply transactions
- Host: GitHub
- URL: https://github.com/go-utils/transactions
- Owner: go-utils
- License: mit
- Created: 2021-01-01T12:10:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-01T15:34:02.000Z (over 5 years ago)
- Last Synced: 2024-06-20T02:01:19.764Z (almost 2 years ago)
- Topics: go, golang, transaction
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# transactions
Simply transactions
# Usage
```go
package main
import (
"context"
"errors"
"github.com/go-utils/transactions"
)
var failure = errors.New("failure")
func main() {
ctx := context.Background()
onTransaction := transactions.OnTransaction(
func(ctx context.Context) error {
return failure
},
)
onRollback := transactions.OnRollback(
func(ctx context.Context, err error) error {
if !errors.Is(err, failure) {
return errors.New("is not `failure` error")
}
return nil
},
)
transaction := transactions.New(onTransaction, onRollback)
if err := transaction.Execute(ctx); err != nil {
panic(err)
}
}
```
# License
[MIT](LICENSE)