Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook func()
Hook is a function that can be added to the revert via the Add() function. These will be run in the reverse order that they were added if the reverter's Fail() function is called.
type Reverter ¶
type Reverter struct {
// contains filtered or unexported fields
}
Reverter is a helper type to manage revert functions.
Example (Fail) ¶
package main import ( "fmt" "github.com/lxc/incus/internal/revert" ) func main() { revert := revert.New() defer revert.Fail() revert.Add(func() { fmt.Println("1st step") }) revert.Add(func() { fmt.Println("2nd step") }) // Revert functions are run in reverse order on return.
Output:
Example (Success) ¶
package main import ( "fmt" "github.com/lxc/incus/internal/revert" ) func main() { revert := revert.New() defer revert.Fail() revert.Add(func() { fmt.Println("1st step") }) revert.Add(func() { fmt.Println("2nd step") }) revert.Success() // Revert functions added are not run on return. }
Output:
func (*Reverter) Clone ¶
Clone returns a copy of the reverter with the current set of revert functions added. This can be used if you want to return a reverting function to an external caller but do not want to actually execute the previously deferred reverter.Fail() function.
Click to show internal directories.
Click to hide internal directories.