Utils methods refactored for readability

This commit is contained in:
srinivasreddy 2016-03-13 00:49:53 +05:30 committed by Steve Francia
parent c42982f76b
commit 6258d48b02

View file

@ -20,35 +20,37 @@ import (
) )
func CheckErr(err error, s ...string) { func CheckErr(err error, s ...string) {
if err != nil { if err == nil {
if len(s) == 0 { return
jww.CRITICAL.Println(err)
} else {
for _, message := range s {
jww.ERROR.Println(message)
}
jww.ERROR.Println(err)
}
} }
if len(s) == 0 {
jww.CRITICAL.Println(err)
return
}
for _, message := range s {
jww.ERROR.Println(message)
}
jww.ERROR.Println(err)
} }
func StopOnErr(err error, s ...string) { func StopOnErr(err error, s ...string) {
if err != nil { if err == nil {
if len(s) == 0 { return
newMessage := err.Error() }
// Printing an empty string results in a error with defer os.Exit(-1)
// no message, no bueno.
if newMessage != "" { if len(s) == 0 {
jww.CRITICAL.Println(newMessage) newMessage := err.Error()
} // Printing an empty string results in a error with
} else { // no message, no bueno.
for _, message := range s { if newMessage != "" {
if message != "" { jww.CRITICAL.Println(newMessage)
jww.CRITICAL.Println(message) }
} }
} for _, message := range s {
if message != "" {
jww.CRITICAL.Println(message)
} }
os.Exit(-1)
} }
} }