gRPC server in Go

Start a gRPC-compatible HTTP/2 server in Go using net/http and golang.org/x/net/http2.

Use the standard net/http package with http2 enabled via http2.ConfigureServer or by setting Protocols to "h2" in Go 1.21+. The server automatically handles HTTP/2 frames, streams, and flow control.

package main

import (
	"log"
	"net/http"
	"golang.org/x/net/http2"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello HTTP/2"))
	})

	server := &http.Server{
		Addr:    ":8443",
		Handler: mux,
	}

	http2.ConfigureServer(server, nil)
	log.Fatal(server.ListenAndServeTLS("cert.pem", "key.pem"))
}