使用HTTP2
1 .在1.6以上的版本,如果使用https模式启动服务器,那么服务器默认将使用HTTP2.0
package main
import(
"net/http"
"golang.org/x/net/http2"
"log"
)
func main(){
var srv http.Server
//http2.VerboseLogs = true
srv.Addr = ":8080"
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello http2"))
})
http2.ConfigureServer(&srv, &http2.Server{})
go func() {
log.Fatal(srv.ListenAndServeTLS("cert.pem", "key.pem"))
}()
select {}
}
有疑问加站长微信联系(非本文作者)