v0.0.188 exerr MVP
This commit is contained in:
@@ -1,23 +1,34 @@
|
||||
package exerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
)
|
||||
|
||||
type ErrorPackageConfig struct {
|
||||
ZeroLogTraces bool // autom print zerolog logs on CreateError
|
||||
RecursiveErrors bool // errors contains their Origin-Error
|
||||
Types []ErrorType // all available error-types
|
||||
ZeroLogErrTraces bool // autom print zerolog logs on .Build() (for SevErr and SevFatal)
|
||||
ZeroLogAllTraces bool // autom print zerolog logs on .Build() (for all Severities)
|
||||
RecursiveErrors bool // errors contains their Origin-Error
|
||||
ExtendedGinOutput bool // Log extended data (trace, meta, ...) to gin in err.Output()
|
||||
Types []ErrorType // all available error-types
|
||||
}
|
||||
|
||||
type ErrorPackageConfigInit struct {
|
||||
LogTraces bool
|
||||
RecursiveErrors bool
|
||||
InitTypes func(_ func(_ string) ErrorType)
|
||||
ZeroLogErrTraces bool
|
||||
ZeroLogAllTraces bool
|
||||
RecursiveErrors bool
|
||||
ExtendedGinOutput bool
|
||||
InitTypes func(_ func(key string, defaultStatusCode *int) ErrorType)
|
||||
}
|
||||
|
||||
var initialized = false
|
||||
|
||||
var pkgconfig = ErrorPackageConfig{
|
||||
ZeroLogTraces: true,
|
||||
RecursiveErrors: true,
|
||||
Types: []ErrorType{TypeInternal},
|
||||
ZeroLogErrTraces: true,
|
||||
ZeroLogAllTraces: false,
|
||||
RecursiveErrors: true,
|
||||
ExtendedGinOutput: false,
|
||||
Types: []ErrorType{TypeInternal, TypePanic, TypeWrap},
|
||||
}
|
||||
|
||||
// Init initializes the exerr packages
|
||||
@@ -30,8 +41,8 @@ func Init(cfg ErrorPackageConfigInit) {
|
||||
|
||||
types := pkgconfig.Types
|
||||
|
||||
fnAddType := func(v string) ErrorType {
|
||||
et := ErrorType{v}
|
||||
fnAddType := func(key string, defaultStatusCode *int) ErrorType {
|
||||
et := ErrorType{key, defaultStatusCode}
|
||||
types = append(types, et)
|
||||
return et
|
||||
}
|
||||
@@ -41,10 +52,23 @@ func Init(cfg ErrorPackageConfigInit) {
|
||||
}
|
||||
|
||||
pkgconfig = ErrorPackageConfig{
|
||||
ZeroLogTraces: cfg.LogTraces,
|
||||
RecursiveErrors: cfg.RecursiveErrors,
|
||||
Types: types,
|
||||
ZeroLogErrTraces: cfg.ZeroLogErrTraces,
|
||||
ZeroLogAllTraces: cfg.ZeroLogAllTraces,
|
||||
RecursiveErrors: cfg.RecursiveErrors,
|
||||
ExtendedGinOutput: cfg.ExtendedGinOutput,
|
||||
Types: types,
|
||||
}
|
||||
|
||||
initialized = true
|
||||
}
|
||||
|
||||
func warnOnPkgConfigNotInitialized() {
|
||||
if !initialized {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("%s\n", langext.StrRepeat("=", 80))
|
||||
fmt.Printf("%s\n", "[WARNING] exerr package used without initializiation")
|
||||
fmt.Printf("%s\n", " call exerr.Init() in your main() function")
|
||||
fmt.Printf("%s\n", langext.StrRepeat("=", 80))
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user