go-utils/common/checkErr.go

28 lines
460 B
Go
Raw Permalink Normal View History

2021-08-11 12:27:54 +00:00
package common
import (
"github.com/sirupsen/logrus"
)
/*
This function checks for an error.
2021-08-19 15:17:58 +00:00
2021-08-11 12:27:54 +00:00
If the error isn't nil it return true and print error otherwise false.
err := errors.New("Test Error")
if common.CheckErr(err, "example error") {
return
}
fmt.Println("No error was found!")
*/
func CheckErr(err error, trace string) bool {
if err != nil {
Log.WithFields(logrus.Fields{
"trace": trace,
}).Error(err)
}
return err != nil
}