Je ne suis peut-être pas très familier avec cela, mais mon serveur de base localhost n'a pas HTTP2 activé pour une raison étrange, je suis normalement proxy derrière Caddy, mais comme je ne veux pas utiliser mon domaine pour ce projet de côté, j'ai créé un serveur de base dans Go, et l'ai couru, cela fonctionne bien, mais les en-têtes montrent HTTP/1.1 au lieu de 2.0, qu'est-ce qui ne va pas?HTTP2 n'est pas activé par défaut sur localhost
package main
import (
"fmt"
"net/http"
"html/template"
"os"
)
func IfError(err error, Quit bool) {
if err != nil {
fmt.Println(err.Error())
if(Quit) {
os.Exit(1);
}
}
}
func ServeHome(w http.ResponseWriter, r *http.Request) {
t, err := template.ParseFiles("html/home")
IfError(err, false)
err = t.Execute(w, nil)
IfError(err, false)
}
func RedirectRoot(fs http.Handler, home http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
home.ServeHTTP(w, r)
} else {
fs.ServeHTTP(w, r)
}
})
}
func main() {
proto := ":8081"
ServeFiles := http.FileServer(http.Dir("static/"))
http.Handle("/", RedirectRoot(ServeFiles, http.HandlerFunc(ServeHome)))
fmt.Printf("Listening on ... %s", proto)
IfError(http.ListenAndServe(proto, nil), true)
}
Très basique, mais ne fonctionne pas même si la documentation dit que cela fonctionne par défaut. En outre, ma version de Go est 1.8.3