Router plugin for dynamic pages in Go

I would like to embed Caddy for serving static files and additionally handle HTTP requests to generate pages directly in Go.
I’m wondering why there is no router plugin for Caddy that allows routing request paths to proper handlers implemented in Go (gorilla like mux).
It seems like the basic functionality but I don’t see it in the docs. Is it because nobody has contributed such plugin or is it assumed to be simple enough to write your own middleware?
Or I am missing something?


I’ve made a simple middleware that delegates all requests to an http.ServeMux (so gorilla would work). It lets me host entire go applications as a caddy middleware.

The initial version of it I’ve been using is at caddy-util/appWrapper.go at master · captncraig/caddy-util · GitHub. Its all broken with caddy 0.9, but I keep meaning to fix it up and document it.

1 Like

Thanks @captncraig

In the meantime I implemented the plugin that works with Caddy 0.9:

I’m still baffled that this is not in the standard set of plugins, especially that adding a new plugin requires modifying caddy source code.

1 Like

Nice work. I’m glad it works for you. I’ll be updating all of my plugins for 0.9 sometime this week and should get around to making that more usable.

Note that there is are tools for helping with some of the “modifications” to caddy source to add this.

I don’t think its a glaring omission, just something that wasn’t conceived of as caddy came around. Proxying go apps was the standard way to do it, until I realized you can just embed your go app.

Configuration handling is still a tricky issue, which I tried to solve with magic. It may or may not still be successful magic, we’ll see.