healthzServer returns a simple health handler which returns ok.
(conn *grpc.ClientConn)
| 58 | |
| 59 | // healthzServer returns a simple health handler which returns ok. |
| 60 | func 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 | |
| 75 | type logResponseWriter struct { |
| 76 | http.ResponseWriter |