caddyserver / xcaddy

Build Caddy with plugins
Apache License 2.0
908 stars 110 forks source link

cmd: add synthetic command `validate-interfaces` #161

Closed mohammed90 closed 5 months ago

mohammed90 commented 9 months ago

The command is injected when running xcaddy with one of Caddy's commands, though validate-interfaces does not exist in Caddy itself. This is useful for guest modules developers to validate their implementation meets the expectation of the host module. Developers who introduce new caddy namespaces and want to participate in the validation process may include code as such in their init:

RegisterType("their.new.namespace", []interface{}{(*Interface1)(nil), (*Interface2)(nil)})

There's dependency on caddyserver/caddy#4838 because the Caddy executable built for the development process expects a version of Caddy that contains certain functions, namely caddy.ConformsToNamespace. I'm not sure if this will break any workflow. We can brainstorm an idea to conditionally inject it, but I can't think of something now.

With this addition, the developer of a Caddy module can run xcaddy validate-interfaces to have a custom Caddy built to receive a message of either All modules conform to their namespaces. or a spit-out of the interface they're missing.

Perhaps validate-types is a better command name? 🤔