Processing POST data

Hi there,
I am using Caddy server to serve static files. I have a contact form that want to process with a go handler function. How do I achieve that? Should I use the reverse proxy feature associated to a go server? I know that if I do everything in the go project directory will work, but I want to have the form in the static content folder that is the root for Caddy.

I would appreciate any help on this.

Yes, the proxy feature should work. Even if the form resides in the root content, it could submit its data to a specific path, like “/formA/”, and Caddy then can forward this particular path to a Go server through its proxy feature.

Other Caddy options (that I did not use yet):

  • fastcgi instead of proxing. There are fcgi client packages available on GitHub.
  • websockets (that would require JavaScript on the client, so maybe way too involved for a simple form. The nice part about Caddy’s websocket directive is that the handler can be a simple cli app that reads from stdin and writes to stdout.)

If I had to process a form, I’d try the proxy first. A Go http server is quickly whipped together…

Thank you so much.
I understand your idea.
My main issue is that I am a newbie so I got stuck while implementing. Right now I have this:
The form is served via Caddy (root directory)
I have a Go process running on port 3000 that should handle the data. I have tested this handler with a /template index.html form and works fine. How do I tell the Caddy server that the POST will be handled by the process running on port 3000?

In general, a entry in the Caddyfile like this should forward the form data to a server listening on port 3000 of the same doman (assuming the form submits to /formdata and the form processing server runs on the same machine): {
    proxy /formdata localhost:3000 {

I am using a proxy directive like this one for making a 3rd-party server available via TLS. I have not much experience with proxying beyond this particular usage; but maybe you can find more info in the Caddy forum.

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