You can run a go routine similar to:

go func() {
        log.Fatal(http.ListenAndServe(":80", http.HandlerFunc(httpToHTTPS)))
}()


//httpToHTTPS redirects all http to https
func httpToHTTPS(w http.ResponseWriter, r *http.Request) {
    http.Redirect(w, r, "https://"+r.Host+r.URL.String(), 
http.StatusMovedPermanently)
}


Regards,

Diego



On Tuesday, September 24, 2019 at 7:37:02 PM UTC-4, Julia Ma wrote:
>
> Hi all,
> I recently realized that request.URL.Scheme is not the correct field to 
> check whether a request is https or not (thank you to this thread 
> <https://groups.google.com/forum/#!searchin/golang-nuts/https$20redirect%7Csort:date/golang-nuts/pMUkBlQBDF0/hifgmKvCAAAJ>
>  
> and other posts on the internet). Once I've determined that the request is 
> http, what do I set the request.TLS to to ensure the redirect is https?
> Thanks,
> Julia
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b700c613-df41-475a-b49d-b30d70015ed8%40googlegroups.com.

Reply via email to