mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00

Move a number of funcs/files in the top-level `main` package into a new `util` package, so test logic can directly invoke functions like RunMark(), etc. The main.go has been trimmed down to minimal sizing, with former supporting funcs moved into `util` package, so they can be run by unit tests. Signed-off-by: Rich Scott <richscott@sent.com>
35 lines
595 B
Go
35 lines
595 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/reconquest/pkg/log"
|
|
)
|
|
|
|
type FatalErrorHandler struct {
|
|
ContinueOnError bool
|
|
}
|
|
|
|
func NewErrorHandler(continueOnError bool) *FatalErrorHandler {
|
|
return &FatalErrorHandler{
|
|
ContinueOnError: continueOnError,
|
|
}
|
|
}
|
|
|
|
func (h *FatalErrorHandler) Handle(err error, format string, args ...interface{}) {
|
|
|
|
if err == nil {
|
|
if h.ContinueOnError {
|
|
log.Error(fmt.Sprintf(format, args...))
|
|
return
|
|
}
|
|
log.Fatal(fmt.Sprintf(format, args...))
|
|
}
|
|
|
|
if h.ContinueOnError {
|
|
log.Errorf(err, format, args...)
|
|
return
|
|
}
|
|
log.Fatalf(err, format, args...)
|
|
}
|