Simple hello world using certmagic in a golang project

I want to write a simple ‘hello’ world project using the cert magic library.

package main

import (

"log"

"net/http"

"time"

)

func timeHandler(w http.ResponseWriter, r *http.Request) {

tm := time.Now().Format(time.RFC1123)

w.Write([]byte("The time is: " + tm))

}

func main() {

mux := http.NewServeMux()

// Convert the timeHandler function to a http.HandlerFunc type.

th := http.HandlerFunc(timeHandler)

// And add it to the ServeMux.

mux.Handle("/time", th)

log.Print("Listening...")

http.ListenAndServe(":8090", mux)

}

// err := certmagic.HTTPS([]string{"example.com", "www.example.com"}, mux)

// if err != nil {

// return err

// }

Where exactly should I wrap the above code to use the certmagic library?

There’s a snippet at the top of the CertMagic readme:

There you go :slight_smile:

1 Like