How to Use gRPC Health Checking in Go

Web
Use the google.golang.org/grpc/health package to register and manage gRPC health checks in Go.

Go's standard library does not include a native gRPC health checking implementation; you must use the google.golang.org/grpc/health package. Register the health service on your gRPC server and implement the Check method to return your service's status.

import (
	"google.golang.org/grpc/health"
	"google.golang.org/grpc/health/grpc_health_v1"
)

// ... inside your server setup
hs := health.NewServer()
hs.SetServingStatus("", grpc_health_v1.HealthCheckResponse_SERVING)

// Register the health service with your gRPC server
grpc_health_v1.RegisterHealthServer(grpcServer, hs)

Use hs.SetServingStatus(service, status) to update the health of specific services, where service is an empty string for the overall server or a specific service name, and status is SERVING, NOT_SERVING, or UNKNOWN.