From 5859cd8dad32fdd7ea55daa5e4377e273fb97a3e Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 29 Apr 2019 09:22:00 -0600 Subject: Instantiate apps that are needed but not explicitly configured --- caddy.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'caddy.go') diff --git a/caddy.go b/caddy.go index 62b12b6..2aa0c6a 100644 --- a/caddy.go +++ b/caddy.go @@ -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. -- cgit v1.2.3