mirror of
https://github.com/kovetskiy/mark.git
synced 2026-04-28 10:32:33 +00:00
Restructure code for more testaability
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>
This commit is contained in:
34
util/error_handler.go
Normal file
34
util/error_handler.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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...)
|
||||
}
|
||||
Reference in New Issue
Block a user