I am creating a custom middleware which has a dependency on a custom app.
There are times the app is shown as not configured what starting up caddy.
How can I enforce the app is created before provisioning the middleware?
Or what work arounds can do?
Yep. The point of AppIfConfigured() is to only provision an app if one was explicitly configured by the user, so another module can choose to “do nothing” or “choose a default” if no config exists. If you expect config to actually exist, then App() is the correct thing to use. The Godoc comment for these methods explain this.
It seems that AppIfConfigured can fail in a module’s provisioning process even if the app configured.
For now I am using the my App’s default state as an error state.
I see, so basically you’re looking for a way to tell apart whether an app was provisioned from no config (default), or actually user-configured. I think that is an ambiguous case with the current API. We should improve that.
I don’t think we should change AppIfConfigured, it has a specific purpose. It specifically documents that it will not load a module if not already loaded.
I think we should add a new AppStrict() which works just like App() (and returns an error if any) which returns an error early if the app is not configured.