mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-22 12:08:28 +08:00
context: Rename func to AppIfConfigured
(#5397)
This commit is contained in:
parent
941eae5f61
commit
f6bab8ba85
19
context.go
19
context.go
|
@ -426,15 +426,20 @@ func (ctx Context) App(name string) (any, error) {
|
||||||
return modVal, nil
|
return modVal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppIsConfigured returns whether an app named name has been
|
// AppIfConfigured returns an app by its name if it has been
|
||||||
// configured. Can be called before calling App() to avoid
|
// configured. Can be called instead of App() to avoid
|
||||||
// instantiating an empty app when that's not desirable.
|
// instantiating an empty app when that's not desirable.
|
||||||
func (ctx Context) AppIsConfigured(name string) bool {
|
func (ctx Context) AppIfConfigured(name string) (any, error) {
|
||||||
if _, ok := ctx.cfg.apps[name]; ok {
|
app, ok := ctx.cfg.apps[name]
|
||||||
return true
|
if !ok || app == nil {
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
appRaw := ctx.cfg.AppsRaw[name]
|
|
||||||
return appRaw != nil
|
appModule, err := ctx.App(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return appModule, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage returns the configured Caddy storage implementation.
|
// Storage returns the configured Caddy storage implementation.
|
||||||
|
|
|
@ -49,20 +49,14 @@ func (a *adminAPI) Provision(ctx caddy.Context) error {
|
||||||
a.ctx = ctx
|
a.ctx = ctx
|
||||||
a.log = ctx.Logger(a) // TODO: passing in 'a' is a hack until the admin API is officially extensible (see #5032)
|
a.log = ctx.Logger(a) // TODO: passing in 'a' is a hack until the admin API is officially extensible (see #5032)
|
||||||
|
|
||||||
// First check if the PKI app was configured, because
|
// Avoid initializing PKI if it wasn't configured
|
||||||
// a.ctx.App() has the side effect of instantiating
|
pkiApp, err := a.ctx.AppIfConfigured("pki")
|
||||||
// and provisioning an app even if it wasn't configured.
|
|
||||||
pkiAppConfigured := a.ctx.AppIsConfigured("pki")
|
|
||||||
if !pkiAppConfigured {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the PKI app, so we can query it for information.
|
|
||||||
appModule, err := a.ctx.App("pki")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
a.pkiApp = appModule.(*PKI)
|
if pkiApp != nil {
|
||||||
|
a.pkiApp = pkiApp.(*PKI)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user