diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-04-29 09:22:00 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-04-29 09:22:00 -0600 |
commit | 5859cd8dad32fdd7ea55daa5e4377e273fb97a3e (patch) | |
tree | 7237ca3c4c1de7f00ca508306b9ef7e427b5553c /caddy.go | |
parent | 43961b542b077f99f78d64629348b9300d3cd4a3 (diff) |
Instantiate apps that are needed but not explicitly configured
Diffstat (limited to 'caddy.go')
-rw-r--r-- | caddy.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -238,11 +238,19 @@ type Handle struct { current *Config } -// App returns the configured app named name. -// A nil value is returned if no app with that -// name is currently configured. -func (h Handle) App(name string) interface{} { - return h.current.apps[name] +// App returns the configured app named name. If no app with +// that name is currently configured, a new empty one will be +// instantiated. (The app module must still be plugged in.) +func (h Handle) App(name string) (interface{}, error) { + if app, ok := h.current.apps[name]; ok { + return app, nil + } + modVal, err := LoadModule(name, nil) + if err != nil { + return nil, fmt.Errorf("instantiating new module %s: %v", name, err) + } + h.current.apps[name] = modVal.(App) + return modVal, nil } // GetStorage returns the configured Caddy storage implementation. |