Пример #1
0
		handler.RegisterManager(grpc)
		go grpc.Serve(lis)
		defer grpc.Stop()

		if httpActive {
			proxyConn, err := component.Identity.Dial()
			if err != nil {
				ctx.WithError(err).Fatal("Could not start client for gRPC proxy")
			}
			mux := runtime.NewServeMux()
			netCtx, cancel := context.WithCancel(context.Background())
			defer cancel()
			pb.RegisterApplicationManagerHandler(netCtx, mux, proxyConn)

			prxy := proxy.WithToken(mux)
			prxy = proxy.WithLogger(prxy, ctx)

			go func() {
				err := http.ListenAndServe(
					fmt.Sprintf("%s:%d", viper.GetString("handler.http-address"), viper.GetInt("handler.http-port")),
					prxy,
				)
				if err != nil {
					ctx.WithError(err).Fatal("Error in gRPC proxy")
				}
			}()
		}

		sigChan := make(chan os.Signal)
		signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
		ctx.WithField("signal", <-sigChan).Info("signal received")
Пример #2
0
		// Register and Listen
		component.RegisterHealthServer(grpc)
		discovery.RegisterRPC(grpc)
		go grpc.Serve(lis)

		if viper.GetString("discovery.http-address") != "" && viper.GetInt("discovery.http-port") != 0 {
			proxyConn, err := component.Identity.Dial()
			if err != nil {
				ctx.WithError(err).Fatal("Could not start client for gRPC proxy")
			}
			mux := runtime.NewServeMux()
			netCtx, cancel := context.WithCancel(context.Background())
			defer cancel()
			pb.RegisterDiscoveryHandler(netCtx, mux, proxyConn)

			prxy := proxy.WithLogger(mux, ctx)

			go func() {
				err := http.ListenAndServe(
					fmt.Sprintf("%s:%d", viper.GetString("discovery.http-address"), viper.GetInt("discovery.http-port")),
					prxy,
				)
				if err != nil {
					ctx.WithError(err).Fatal("Error in gRPC proxy")
				}
			}()
		}

		sigChan := make(chan os.Signal)
		signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
		ctx.WithField("signal", <-sigChan).Info("signal received")