From f2370fec2fd34869401b9026f2574a6aedaf1356 Mon Sep 17 00:00:00 2001 From: aveyuan Date: Mon, 26 Aug 2024 11:46:47 +0800 Subject: [PATCH] add IgnoreViewLoadError config --- configuration.go | 15 +++++++++++++++ iris.go | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/configuration.go b/configuration.go index 848354d93b..870a07d42d 100644 --- a/configuration.go +++ b/configuration.go @@ -223,6 +223,13 @@ func NonBlocking() Configurator { } } +// IgnoreViewLoadError Server Runing, When View load has error will be ignore. +func IgnoreViewLoadError() Configurator { + return func(app *Application) { + app.config.IgnoreViewLoadError = true + } +} + // WithoutServerError will cause to ignore the matched "errors" // from the main application's `Run/Listen` function. // @@ -976,6 +983,9 @@ type Configuration struct { // // Defaults to empty map. Other map[string]interface{} `ini:"other" json:"other,omitempty" yaml:"Other" toml:"Other"` + + // IgnoreViewLoadError Server Runing, When View load has error will be ignore + IgnoreViewLoadError bool } var _ context.ConfigurationReadOnly = (*Configuration)(nil) @@ -1186,6 +1196,11 @@ func (c *Configuration) GetOther() map[string]interface{} { return c.Other } +// GetIgnoreViewLoadError returns the IgnoreViewLoadError field. +func (c *Configuration) GetIgnoreViewLoadError() bool { + return c.IgnoreViewLoadError +} + // WithConfiguration sets the "c" values to the framework's configurations. // // Usage: diff --git a/iris.go b/iris.go index fa0ece7826..3b8a4bd17c 100644 --- a/iris.go +++ b/iris.go @@ -740,7 +740,11 @@ func (app *Application) Build() error { app.view.AddFunc("urlpath", rv.Path) // app.view.AddFunc("url", rv.URL) if err := app.view.Load(); err != nil { - return fmt.Errorf("build: view engine: %v", err) + if app.config.IgnoreViewLoadError { + app.logger.Errorf("build: view engine: %v", err) + } else { + return fmt.Errorf("build: view engine: %v", err) + } } }