MCPcopy
hub / github.com/caddyserver/caddy / AppIfConfigured

Method AppIfConfigured

context.go:530–546  ·  view source on GitHub ↗

AppIfConfigured is like App, but it returns an error if the app has not been configured. This is useful when the app is required and its absence is a configuration error; or when the app is optional and you don't want to instantiate a new one that hasn't been explicitly configured. If the app is not

(name string)

Source from the content-addressed store, hash-verified

528// new one that hasn't been explicitly configured. If the app
529// is not in the configuration, the error wraps ErrNotConfigured.
530func (ctx Context) AppIfConfigured(name string) (any, error) {
531 if ctx.cfg == nil {
532 return nil, fmt.Errorf("app module %s: %w", name, ErrNotConfigured)
533 }
534 // if the app failed to load before, return the cached error
535 if err, ok := ctx.cfg.failedApps[name]; ok {
536 return nil, fmt.Errorf("loading %s app module: %v", name, err)
537 }
538 if app, ok := ctx.cfg.apps[name]; ok {
539 return app, nil
540 }
541 appRaw := ctx.cfg.AppsRaw[name]
542 if appRaw == nil {
543 return nil, fmt.Errorf("app module %s: %w", name, ErrNotConfigured)
544 }
545 return ctx.App(name)
546}
547
548// ErrNotConfigured indicates a module is not configured.
549var ErrNotConfigured = fmt.Errorf("module not configured")

Callers 6

ProvisionMethod · 0.80
ProvisionMethod · 0.80
ProvisionMethod · 0.80
TLSConfigMethod · 0.80
CleanupMethod · 0.80
ProvisionMethod · 0.80

Calls 1

AppMethod · 0.95

Tested by

no test coverage detected