| 55 | var _ pb.EchoServer = &echoServer{} |
| 56 | |
| 57 | func 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 | } |