Custom directive, `Unknown directive` error

I’m working on a plugin to add support for rendering templates with Jet to Caddy. I’ve modified run.go and plugins.go but something’s causing them to not load properly during compilation; a git diff master in the Caddy repo shows

diff --git a/caddy/caddymain/run.go b/caddy/caddymain/run.go
index ddc50aa..8143d0d 100644
--- a/caddy/caddymain/run.go
+++ b/caddy/caddymain/run.go
@@ -35,6 +35,7 @@ import (

        // This is where other plugins get plugged in (imported)
+       _ ""

 func init() {
diff --git a/caddyhttp/httpserver/plugin.go b/caddyhttp/httpserver/plugin.go
index ad2d873..cc6d709 100644
--- a/caddyhttp/httpserver/plugin.go
+++ b/caddyhttp/httpserver/plugin.go
@@ -578,6 +578,7 @@ var directives = []string{
        "datadog",    //
        "prometheus", //
+       "jet",        //
        "cgi", //

Is there a part I’m missing? Can Caddy be built for a custom plugin with the simple go run build.go? The jet plugin doesn’t show up in caddy -plugins. We should also update the documentation because it’s not very clear on this.

Does your plugin register itself with Caddy? And are you sure you’re running build.go in the right copy of the Caddy repo?

No to both (I think; it doesn’t show up with caddy -plugins at least). What is the right copy of the Caddy repo?

What is your plugin’s code? Make sure that you are registering it in an init(), like this:

The right copy of the Caddy repo would be the one in your $GOPATH, from which you are running go run build.go, and to make sure that your plugin imports that package. Just make sure your paths and git branch and stuff are all correct.

1 Like

OK, the problem was I was building outside of my $GOPATH. Thanks for the help!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.