Add plugin to directives automatically?

I think I’ve seen some discussion on this, but I can’t remember.

Would it make sense to automatically add a plugin to the directive’s list when you register it? This sidesteps the need for also editing a caddy or coredns source file to add your directive?

1 Like

Yes, this is now possible with the HTTP server: httpserver.RegisterDevDirective() - but it must be used only for convenience in development!

RegisterDevDirective splices name into the list of directives immediately before another directive. This function is ONLY for plugin development purposes! NEVER use it for a plugin that you are not currently building. If before is empty, the directive will be appended to the end of the list.

It is imperative that directives execute in the proper order, and hard-coding the list of directives guarantees a correct, absolute order every time. This function is convenient when developing a plugin, but it does not guarantee absolute ordering. Multiple plugins registering directives with this function will lead to non- deterministic builds and buggy software.

Directive names must be lower-cased and unique. Any errors here are fatal, and even successful calls print a message to stdout as a reminder to use it only in development.

You can, of course, do what you want for the DNS server, however I recommend absolute ordering as the relative ordering has the potential to be buggy as it is non-deterministic.

I knew that I saw you say something like that! Thanks. Only for development… I think this would be useful for prod as well and that people will actually use is for that.

This saves the hassle of fiddling with the directives list in Caddy, which is a big plus IMHO.

You think so now, but then your builds are non-deterministic… and then what if two plugins depend on each other (each are inserted into the list “before” each other) – then what.

Noted. I’ve copied RegisterDevPlugin (verbatim!) into coredns.


I/we have the same “trouble” with the directives list. You have to “fork” the repo to get your own plugin in.

If you only load one more plugin using RegisterDevPlugin, will the build still be non-deterministic???
The order isn’t crucial for the plugin we are adding


Rather than dredge up a 3-year-old thread, please start a new one… Caddy 2 doesn’t have this problem, and it’s already on beta 6, so give it a try on the v2 branch. Docs are in the wiki.

(And to answer your question: no, the build is not non-deterministic, it’s the middleware chain that is non-deterministic.)