MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

examples/features/health/server/main.go:57–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55var _ pb.EchoServer = &echoServer{}
56
57func main() {
58 flag.Parse()
59
60 lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
61 if err != nil {
62 log.Fatalf("failed to listen: %v", err)
63 }
64
65 s := grpc.NewServer()
66 healthcheck := health.NewServer()
67 healthgrpc.RegisterHealthServer(s, healthcheck)
68 pb.RegisterEchoServer(s, &echoServer{})
69
70 go func() {
71 // asynchronously inspect dependencies and toggle serving status as needed
72 next := healthpb.HealthCheckResponse_SERVING
73
74 for {
75 healthcheck.SetServingStatus(system, next)
76
77 if next == healthpb.HealthCheckResponse_SERVING {
78 next = healthpb.HealthCheckResponse_NOT_SERVING
79 } else {
80 next = healthpb.HealthCheckResponse_SERVING
81 }
82
83 time.Sleep(*sleep)
84 }
85 }()
86
87 if err := s.Serve(lis); err != nil {
88 log.Fatalf("failed to serve: %v", err)
89 }
90}

Callers

nothing calls this directly

Calls 6

SetServingStatusMethod · 0.95
ServeMethod · 0.95
NewServerFunction · 0.92
NewServerFunction · 0.92
ParseMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected