1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package main
import (
"net/http"
)
// redirect http to https with noop middleware
func httpsRedirect() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.TLS == nil {
target := "https://" + r.Host + r.URL.RequestURI()
http.Redirect(w, r, target, http.StatusMovedPermanently)
return
}
w.WriteHeader(http.StatusOK)
})
}