package main import ( "context" "errors" "time" ) type Entity struct { Name string Address string } type GetName struct { UID string Sleep time.Duration Result Entity } func (b *GetName) CorrelationID() string { return b.UID } func (b *GetName) Execute(context.Context) error { b.Result = Entity{Name: "Bob"} if b.Sleep > 0 { time.Sleep(b.Sleep) } return nil } func (b *GetName) Rollback(context.Context) error { b.Result = Entity{} return nil } type GetAddress struct { Input *Entity Result Entity } func (b *GetAddress) CorrelationID() string { return b.Input.Name } func (b *GetAddress) Execute(context.Context) error { b.Result = *b.Input if b.Result.Address != "" { return errors.New("already set") } b.Result.Address = "London" return nil } func (b *GetAddress) Rollback(context.Context) error { b.Result = Entity{} return nil }