forked from TrueCloudLab/restic
Add BreakIf function
This commit is contained in:
parent
3d768e39ea
commit
6aed4035f5
2 changed files with 13 additions and 0 deletions
|
@ -148,6 +148,8 @@ func Log(tag string, f string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Break stopts the program if the debug tag is active and the string in tag is
|
||||||
|
// contained in the DEBUG_BREAK environment variable.
|
||||||
func Break(tag string) {
|
func Break(tag string) {
|
||||||
// check if breaking is enabled
|
// check if breaking is enabled
|
||||||
if v, ok := opts.breaks[tag]; !ok || !v {
|
if v, ok := opts.breaks[tag]; !ok || !v {
|
||||||
|
@ -166,3 +168,12 @@ func Break(tag string) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BreakIf stopts the program if the debug tag is active and the string in tag
|
||||||
|
// is contained in the DEBUG_BREAK environment variable and the return value of
|
||||||
|
// fn is true.
|
||||||
|
func BreakIf(tag string, fn func() bool) {
|
||||||
|
if fn() {
|
||||||
|
Break(tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,3 +5,5 @@ package debug
|
||||||
func Log(tag string, fmt string, args ...interface{}) {}
|
func Log(tag string, fmt string, args ...interface{}) {}
|
||||||
|
|
||||||
func Break(string) {}
|
func Break(string) {}
|
||||||
|
|
||||||
|
func BreakIf(string, func() bool) {}
|
||||||
|
|
Loading…
Reference in a new issue