aboutsummaryrefslogtreecommitdiffhomepage
path: root/context.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2023-02-27 13:58:27 -0500
committerGitHub <[email protected]>2023-02-27 18:58:27 +0000
commitf6bab8ba85b231ea0930282e684c0040001059e6 (patch)
tree39b9e43536a582e423625e8f04d68a98ea8e3675 /context.go
parent941eae5f615aeaf038f62002e673a7bf4886f1c7 (diff)
downloadcaddy-f6bab8ba85b231ea0930282e684c0040001059e6.tar.gz
caddy-f6bab8ba85b231ea0930282e684c0040001059e6.zip
context: Rename func to `AppIfConfigured` (#5397)
Diffstat (limited to 'context.go')
-rw-r--r--context.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/context.go b/context.go
index c585aa55d..fcefad199 100644
--- a/context.go
+++ b/context.go
@@ -426,15 +426,20 @@ func (ctx Context) App(name string) (any, error) {
return modVal, nil
}
-// AppIsConfigured returns whether an app named name has been
-// configured. Can be called before calling App() to avoid
+// AppIfConfigured returns an app by its name if it has been
+// configured. Can be called instead of App() to avoid
// instantiating an empty app when that's not desirable.
-func (ctx Context) AppIsConfigured(name string) bool {
- if _, ok := ctx.cfg.apps[name]; ok {
- return true
+func (ctx Context) AppIfConfigured(name string) (any, error) {
+ app, ok := ctx.cfg.apps[name]
+ 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.