📝 Add godocs
This commit is contained in:
parent
2324d738bc
commit
e736978b93
3 changed files with 31 additions and 0 deletions
12
options.go
12
options.go
|
|
@ -12,12 +12,18 @@ type config struct {
|
|||
transformers []Transformer
|
||||
}
|
||||
|
||||
// A function which should be used to log the responded error.
|
||||
type LoggerFunc func(*gin.Context, rErrors.ResponsableError)
|
||||
|
||||
// A function which should potentially return a [rErrors.ResponsableError] which wraps the provided error.
|
||||
type Transformer func(error) rErrors.ResponsableError
|
||||
|
||||
// An option that customizes the behavior of [ErrorMiddleware]
|
||||
type Option func(config) config
|
||||
|
||||
// Provides an [Option] which adds the specified [LoggerFunc] to the [ErrorMiddleware]
|
||||
//
|
||||
// Multiple [LoggerFunc] may be added.
|
||||
func WithLogger(logger LoggerFunc) Option {
|
||||
return func(c config) config {
|
||||
c.loggers = append(c.loggers, logger)
|
||||
|
|
@ -25,6 +31,9 @@ func WithLogger(logger LoggerFunc) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// Provides an [Option] which adds the specified [Transformer] to the [ErrorMiddleware]
|
||||
//
|
||||
// Multiple [Transformer] may (and probably should) be added.
|
||||
func WithTransformer(tr Transformer) Option {
|
||||
return func(c config) config {
|
||||
c.transformers = append(c.transformers, tr)
|
||||
|
|
@ -32,6 +41,9 @@ func WithTransformer(tr Transformer) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// Provides an [Option] which adds the default [Transformer] to the [ErrorMiddleware]
|
||||
//
|
||||
// This [Transformer] handles a [gin.Error].
|
||||
func WithDefaultTransformer() Option {
|
||||
return WithTransformer(ginTransformer)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue