Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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/lxd/lxd/revert"
)
func main() {
revert := revert.New()
defer revert.Fail()
revert.Add(func() { fmt.Println("1st step") })
revert.Add(func() { fmt.Println("2nd step") })
return // Revert functions are run in reverse order on return.
}
Output: 2nd step 1st step
Example (Success) ¶
package main
import (
"fmt"
"github.com/lxc/lxd/lxd/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.
return
}
func (*Reverter) Add ¶
func (r *Reverter) Add(f func())
Add adds a revert function to the list to be run when Revert() is called.
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.