Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "errors"
- )
- type InfrastructureAction interface {
- Apply()
- Recovery()
- }
- type RecoveryStack []InfrastructureAction
- type Step1 struct {
- id string
- }
- type Step2 struct {
- id string
- }
- func (s Step1) Apply() {
- fmt.Println("Step1 apply", s.id)
- }
- func (s Step1) Recovery() {
- fmt.Println("Step1 recovery", s.id)
- }
- func (s Step2) Apply() {
- fmt.Println("Step2 apply", s.id)
- }
- func (s Step2) Recovery() {
- fmt.Println("Step2 recovery", s.id)
- }
- func Perform() (err error) {
- defer func() {
- if r := recover(); r != nil {
- err = r.(error)
- }
- }()
- GoesWrong()
- return
- }
- func GoesWrong() {
- panic(errors.New("Fail"))
- }
- func main() {
- var s1 InfrastructureAction = &Step1{"some_unique_id_for_step1"}
- var s2 InfrastructureAction = &Step2{"some_unique_id_for_step2"}
- var rStack RecoveryStack
- rStack = append(rStack, s1)
- rStack = append(rStack, s2)
- for idx, _ := range rStack {
- rStack[idx].Apply()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement