2013-10-09 22:52:29 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2014-03-31 17:23:34 +00:00
|
|
|
|
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
2013-10-09 22:52:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func CheckErr(err error, s ...string) {
|
|
|
|
if err != nil {
|
2014-06-30 04:32:53 +00:00
|
|
|
if len(s) == 0 {
|
|
|
|
jww.CRITICAL.Println(err)
|
|
|
|
} else {
|
|
|
|
for _, message := range s {
|
|
|
|
jww.ERROR.Println(message)
|
|
|
|
}
|
2014-09-06 01:38:36 +00:00
|
|
|
jww.ERROR.Println(err)
|
2013-10-09 22:52:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 23:06:47 +00:00
|
|
|
func StopOnErr(err error, s ...string) {
|
2013-10-09 22:52:29 +00:00
|
|
|
if err != nil {
|
2015-02-17 10:35:23 +00:00
|
|
|
if len(s) == 0 {
|
2015-10-05 18:26:49 +00:00
|
|
|
newMessage := err.Error()
|
2014-08-23 21:12:36 +00:00
|
|
|
|
2015-02-17 10:35:23 +00:00
|
|
|
// Printing an empty string results in a error with
|
|
|
|
// no message, no bueno.
|
|
|
|
if newMessage != "" {
|
|
|
|
jww.CRITICAL.Println(newMessage)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, message := range s {
|
|
|
|
if message != "" {
|
|
|
|
jww.CRITICAL.Println(message)
|
|
|
|
}
|
2014-06-30 04:32:53 +00:00
|
|
|
}
|
2014-03-31 17:23:34 +00:00
|
|
|
}
|
2015-02-17 10:35:23 +00:00
|
|
|
os.Exit(-1)
|
2013-10-09 22:52:29 +00:00
|
|
|
}
|
|
|
|
}
|