1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-06 03:27:27 +00:00

omit errors received by the server via configuration 🍪 | requested by https://github.com/kataras/iris/issues/668

relative link: https://github.com/kataras/iris/issues/668


Former-commit-id: 6491abd68b74e18bf4ed0b32406e67597c9b55a9
This commit is contained in:
hiveminded
2017-07-13 16:31:36 +03:00
parent ace439203d
commit 16ccb2edc4
12 changed files with 294 additions and 64 deletions

View File

@@ -95,6 +95,29 @@ type Configurator func(*Application)
// variables for configurators don't need any receivers, functions
// for them that need (helps code editors to recognise as variables without parenthesis completion).
// WithoutServerError will cause to ignore the matched "errors"
// from the main application's `Run` function.
//
// Usage:
// err := app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
// will return `nil` if the server's error was `http/iris#ErrServerClosed`.
//
// See `Configuration#IgnoreServerErrors []string` too.
func WithoutServerError(errors ...error) Configurator {
return func(app *Application) {
if len(errors) == 0 {
return
}
errorsAsString := make([]string, len(errors), len(errors))
for i, e := range errors {
errorsAsString[i] = e.Error()
}
app.config.IgnoreServerErrors = append(app.config.IgnoreServerErrors, errorsAsString...)
}
}
// WithoutStartupLog turns off the information send, once, to the terminal when the main server is open.
var WithoutStartupLog = func(app *Application) {
app.config.DisableStartupLog = true
@@ -220,6 +243,17 @@ type Configuration struct {
// It can be retrieved by the context if needed (i.e router for subdomains)
vhost string
// IgnoreServerErrors will cause to ignore the matched "errors"
// from the main application's `Run` function.
// This is a slice of string, not a slice of error
// users can register these errors using yaml or toml configuration file
// like the rest of the configuration fields.
//
// See `WithoutServerError(...)` function too.
//
// Defaults to an empty slice.
IgnoreServerErrors []string `yaml:"IgnoreServerErrors" toml:"IgnoreServerErrors"`
// DisableStartupLog if setted to true then it turns off the write banner on server startup.
//
// Defaults to false.
@@ -455,6 +489,10 @@ func WithConfiguration(c Configuration) Configurator {
return func(app *Application) {
main := app.config
if v := c.IgnoreServerErrors; len(v) > 0 {
main.IgnoreServerErrors = append(main.IgnoreServerErrors, v...)
}
if v := c.DisableStartupLog; v {
main.DisableStartupLog = v
}