http2 is an implementation of HTTP/2 protocol for fasthttp.
go get github.com/dgrr/http2@v0.2.12
If you need any help to set up, contributing or understanding this repo, you can contact me on gofiber's Discord.
The server can only be used if your server supports TLS. Then, you can call ConfigureServer.
package main
import (
"github.com/valyala/fasthttp"
"github.com/dgrr/http2"
)
func main() {
s := &fasthttp.Server{
Handler: yourHandler,
Name: "HTTP2 test",
}
http2.ConfigureServer(s, http2.ServerConfig{})
s.ListenAndServeTLS(...)
}
The HTTP/2 client only works with the HostClient.
package main
import (
"fmt"
"log"
"github.com/dgrr/http2"
"github.com/valyala/fasthttp"
)
func main() {
hc := &fasthttp.HostClient{
Addr: "api.binance.com:443",
}
if err := http2.ConfigureClient(hc, http2.ClientOpts{}); err != nil {
log.Printf("%s doesn't support http/2\n", hc.Addr)
}
statusCode, body, err := hc.Get(nil, "https://api.binance.com/api/v3/time")
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%d: %s\n", statusCode, body)
}