mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-03 22:33:28 +00:00
Instantiate apps that are needed but not explicitly configured
This commit is contained in:
parent
43961b542b
commit
5859cd8dad
4 changed files with 44 additions and 19 deletions
18
caddy.go
18
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue