In Ruby/Rack, I'm able to get the scheme of the current request URL from scheme#request
. However, in Go, http.Request.URL.Scheme
returns an empty string:
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%#v
", r.URL.Scheme) // Always shows empty string
}
How do I get scheme of the current request URL?