Skip to content

Commit

Permalink
Use the golang.org/x/net/http2/h2c module
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Nov 27, 2024
1 parent cafe1de commit 0ca28d7
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
golang.org/x/net v0.26.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)
Expand Down Expand Up @@ -63,7 +64,6 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions pkg/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"

pb "github.com/grafana/quickpizza/pkg/grpc/quickpizza"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -45,13 +47,13 @@ func NewServer(listen string, healthzListen string) *Server {

func (s *Server) listenHealthz() {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("/grpchealthz", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusNoContent)
})

health := &http.Server{
Addr: s.healthzListen,
Handler: mux,
Handler: h2c.NewHandler(mux, &http2.Server{}),
}

slog.Info("Starting QuickPizza gRPC health check server", "listenAddress", s.healthzListen)
Expand Down
240 changes: 240 additions & 0 deletions vendor/golang.org/x/net/http2/h2c/h2c.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ golang.org/x/mod/semver
## explicit; go 1.18
golang.org/x/net/http/httpguts
golang.org/x/net/http2
golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/internal/timeseries
Expand Down

0 comments on commit 0ca28d7

Please sign in to comment.