How do I serve on HTTP/2 with Gin in Go?

To serve your Gin application over HTTP/2, you will first need to ensure that your server is set up properly. Below is a basic example of setting up a Gin server with HTTP/2 support.

package main import ( "log" "net/http" "github.com/gin-gonic/gin" "golang.org/x/net/http2" ) func main() { router := gin.Default() router.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "Hello, HTTP/2!"}) }) server := &http.Server{ Addr: ":8080", Handler: router, } http2.ConfigureServer(server) log.Println("Serving on https://localhost:8080") log.Fatal(server.ListenAndServeTLS("server.crt", "server.key")) }

Serving HTTP/2 with Gin Go Gin framework HTTP/2 server Go Gin web server example