mirror of
https://github.com/kovetskiy/mark.git
synced 2026-04-18 12:11:12 +00:00
33 lines
591 B
Go
33 lines
591 B
Go
package util
|
|
|
|
import (
|
|
"github.com/rs/zerolog/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().Msgf(format, args...)
|
|
return
|
|
}
|
|
log.Fatal().Msgf(format, args...)
|
|
}
|
|
|
|
if h.ContinueOnError {
|
|
log.Error().Err(err).Msgf(format, args...)
|
|
return
|
|
}
|
|
log.Fatal().Err(err).Msgf(format, args...)
|
|
}
|