-
Notifications
You must be signed in to change notification settings - Fork 202
/
activity.go
60 lines (49 loc) · 1.31 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package saga
import (
"context"
"errors"
"fmt"
)
func Withdraw(ctx context.Context, transferDetails TransferDetails) error {
fmt.Printf(
"\nWithdrawing $%f from account %s. ReferenceId: %s\n",
transferDetails.Amount,
transferDetails.FromAccount,
transferDetails.ReferenceID,
)
return nil
}
func WithdrawCompensation(ctx context.Context, transferDetails TransferDetails) error {
fmt.Printf(
"\nWithdrawing compensation $%f from account %s. ReferenceId: %s\n",
transferDetails.Amount,
transferDetails.FromAccount,
transferDetails.ReferenceID,
)
return nil
}
func Deposit(ctx context.Context, transferDetails TransferDetails) error {
fmt.Printf(
"\nDepositing $%f into account %s. ReferenceId: %s\n",
transferDetails.Amount,
transferDetails.ToAccount,
transferDetails.ReferenceID,
)
return nil
}
func DepositCompensation(ctx context.Context, transferDetails TransferDetails) error {
fmt.Printf(
"\nDepositing compensation $%f into account %s. ReferenceId: %s\n",
transferDetails.Amount,
transferDetails.ToAccount,
transferDetails.ReferenceID,
)
return nil
}
func StepWithError(ctx context.Context, transferDetails TransferDetails) error {
fmt.Printf(
"\nSimulate failure to trigger compensation. ReferenceId: %s\n",
transferDetails.ReferenceID,
)
return errors.New("some error")
}