Skip to content

Commit

Permalink
add IgnoreViewLoadError config
Browse files Browse the repository at this point in the history
  • Loading branch information
aveyuan committed Aug 26, 2024
1 parent 6776bf0 commit f2370fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion iris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit f2370fe

Please sign in to comment.