Documentation
¶
Overview ¶
Package deferhelper contains defer-related helpers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeforeAfter ¶
func BeforeAfter(before, after func()) func()
BeforeAfter, if called in the following manner from a defer statement at the very beginning of a function,
func Example() {
defer deferhelper.BeforeAfter(before(), after())()
// do something
}
will call 'before' function before executing the function code and 'after' function after executing the function code.
Example ¶
defer BeforeAfter(func() { fmt.Println("before") }, func() { fmt.Println("after") })()
fmt.Println("in the middle")
Output: before in the middle after
func WriteBeforeAfter ¶
WriteBeforeAfter is like BeforeAfter but writes 'before' and 'after' slices to 'w' before and after executing the function code. It panics if a write to 'w' fails.
func WriteStringBeforeAfter ¶
WriteStringBeforeAfter is like WriteBeforeAfter but accepts strings. It panics if a write to 'w' fails.
Example ¶
defer WriteStringBeforeAfter(os.Stdout, "", "")()
defer WriteStringBeforeAfter(os.Stdout, "only before\n", "")()
defer WriteStringBeforeAfter(os.Stdout, "before\n", "after\n")()
defer WriteStringBeforeAfter(os.Stdout, "", "only after\n")()
fmt.Println("in the middle")
Output: only before before in the middle only after after
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.