Can I write server side code in GO in Caddy?

Hello all
I didn’t found any beginner subforum, i have few questions about Caddy web server .

  1. Can i write dynamic server site logic with GO in Caddy?
    That is like web app similar to war in java’s tomcat .
  2. if yes can you please provide good links for tutorials ?
    if not please recommend me on GO server which enable to write GO server side code

I want to know the creators perspective on this as well.

Personally i will use caddy as a base only if i want to add functionality on top of a webserver / proxy server.

Caddy has wonderful docs on how you can extend Caddy to add your custom logic - Extending Caddy — Caddy Documentation

For everything else, i would stick to the standard http library (Go by Example: HTTP Servers) or using something like gin (GitHub - gin-gonic/gin: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.)

But again, this is my personal opinion. Would like to know the maintainer’s views on this.

1 Like

Yeah, Caddy v2 is more of an “app platform”, where you plug your own code into it. It’s not really meant to be used as a library. It’s probably possible to do it, but no docs have been written about it and no extra effort has been made to make that usecase viable.

If you want to write your own server code instead, you can use certmagic as a library to provide you with automatic HTTPS; it was designed for use in Caddy as a library, and others have had success with it in their own projects as well.

And if you don’t want to worry about TLS at all, you can use Caddy as a reverse proxy that terminates TLS, and run your own server separately behind Caddy.

1 Like

Thanks for your replays folks
but i still dont understand
i need something like java tomcat , i like to replace it as i don’t what to relay on any JVM
i want a fast self-contained static linked web server .
write GO server code as the business logic
And yes SSL support
i really don’t what some side option or hack but the real standard way to write server code .
And way to able to find documentation and support when needed
Thanks !

I don’t know for sure, but it seems FastCGI would work with GO programs. I am still new to Caddy, but I am using PHP for my application logic and it works great with Caddy.

1 Like

We usually don’t follow the “tomcat” kind of an approach. Sure you can achieve that using clever hacks like using go plugins (, but it’s not the standard way of doing things in Go.

Usually, go programs are self sufficient and can have an http server embedded in them. Refer to the links I’ve shared in the previous comment.

1 Like

Yep, Caddy is a platform which you can extend.

Yes, although a Tomcat-like approach is not necessary/conventional in Go, as others have stated.

I tend to agree.

Caddy will do the TLS for you, but if you’re not using Caddy and just writing a Go program instead, use CertMagic: GitHub - caddyserver/certmagic: Automatic HTTPS for any Go program: fully-managed TLS certificate issuance and renewal

where can i find the tutorial on extending and writing GO code in server-side ?

First reply:

This topic was automatically closed after 30 days. New replies are no longer allowed.