How to apply new TLS configuration for HTTPS server in Go Fiber

1.4k Views Asked by At

I use Go Fiber for TLS server. How I can apply new configuration to TLS server without restart application?

For example I have code

    app := fiber.New()

    m := &autocert.Manager{
        Prompt: autocert.AcceptTOS,
        HostPolicy: autocert.HostWhitelist("example.com", "example.net"),
        Cache: autocert.DirCache("./certs"),
    }

    cfg := &tls.Config{
        GetCertificate: m.GetCertificate,
        NextProtos: []string{
            "http/1.1", "acme-tls/1",
        },
    }
    ln, err := tls.Listen("tcp", ":443", cfg)
    if err != nil {
        panic(err)
    }

    log.Fatal(app.Listener(ln))

I would like to setup a new list of domains for TLS server.

HostPolicy: autocert.HostWhitelist("example1.org", "example1.info"),

If it is possible to apply the new TLS configuration without restart the server, it would be better

1

There are 1 best solutions below

0
On

I don't think this is possible and I don't think you should change the domain during runtime. I like the combination of Fiber and Certmagic, but I would do it in a different way:

func main() {
    app := fiber.New()

    ln, err := certmagic.Listen([]string{"example.com"})
    if err != nil {
        panic(err)
    }

    log.Fatal(app.Listener(ln))
}