2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-31 08:00:48 +00:00

Add BreakIf function

This commit is contained in:
Alexander Neumann 2015-03-15 14:00:28 +01:00
parent 3d768e39ea
commit 6aed4035f5
2 changed files with 13 additions and 0 deletions

View File

@ -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) {
// check if breaking is enabled
if v, ok := opts.breaks[tag]; !ok || !v {
@ -166,3 +168,12 @@ func Break(tag string) {
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)
}
}

View File

@ -5,3 +5,5 @@ package debug
func Log(tag string, fmt string, args ...interface{}) {}
func Break(string) {}
func BreakIf(string, func() bool) {}