Documentation ¶
Overview ¶
Package undo contains abstractions for working with a stack of state changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack models a simple undo stack which consumers can use to store undo stateful functions, such as a function to teardown API state if something goes wrong during procedural commands, for example deleting a Fastly service after it's been created.
func (*Stack) Pop ¶
Pop method pops last added Fn element off the stack and returns it. If stack is empty Pop() returns nil.
func (*Stack) RunIfError ¶
RunIfError unwinds the stack if a non-nil error is passed, by serially calling each Fn function state in FIFO order. If any Fn returns an error, it gets logged to the provided writer. Should be deferrerd, such as:
undoStack := undo.NewStack() defer func() { undoStack.RunIfError(w, err) }()