MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / healthzServer

Function healthzServer

examples/internal/gateway/handlers.go:60–73  ·  view source on GitHub ↗

healthzServer returns a simple health handler which returns ok.

(conn *grpc.ClientConn)

Source from the content-addressed store, hash-verified

58
59// healthzServer returns a simple health handler which returns ok.
60func healthzServer(conn *grpc.ClientConn) http.HandlerFunc {
61 return func(w http.ResponseWriter, r *http.Request) {
62 w.Header().Set("Content-Type", "text/plain")
63 if s := conn.GetState(); s == connectivity.Idle {
64 // Invoke method to move connection from Idle to Ready
65 conn.Invoke(r.Context(), "/grpc.health.v1.Health/Check", &emptypb.Empty{}, &emptypb.Empty{})
66 }
67 if s := conn.GetState(); s != connectivity.Ready {
68 http.Error(w, fmt.Sprintf("grpc server is %s", s), http.StatusBadGateway)
69 return
70 }
71 fmt.Fprintln(w, "ok")
72 }
73}
74
75type logResponseWriter struct {
76 http.ResponseWriter

Callers 1

RunFunction · 0.85

Calls 4

SetMethod · 0.80
HeaderMethod · 0.80
GetStateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected