Quoting the documentation of the caddy.Module, we find this:
Modules will often implement additional interfaces including Provisioner, Validator, and CleanerUpper. If a module implements these interfaces, their methods are called during the module’s lifespan.
When a module is loaded by a host module, the following happens:
- ModuleInfo.New() is called to get a new instance of the module.
- The module’s configuration is unmarshaled into that instance.
- If the module is a Provisioner, the Provision() method is called.
- If the module is a Validator, the Validate() method is called.
- The module will probably be type-asserted from interface{} to some other, more useful interface expected by the host > module. For example, HTTP handler modules are type-asserted as caddyhttp.MiddlewareHandler values.
- When a module’s containing Context is canceled, if it is a CleanerUpper, its Cleanup() method is called.
To say it differently: