Пример #1
0
func (s *Server) ListenGRPC() error {
	grpcPort := s.Config.GetGrpcPortString()
	//Listen
	lis, err := net.Listen("tcp", grpcPort)
	if err != nil {
		return fmt.Errorf("server.go: failed to listen: %v", err)
	}

	var opts []grpc.ServerOption
	if s.Config.TlsCertFile != "" && s.Config.TlsKeyFile != "" {
		creds, err := credentials.NewServerTLSFromFile(s.Config.TlsCertFile, s.Config.TlsKeyFile)
		if err != nil {
			log.Fatalf("server.go: Failed to generate credentials %v", err)
		}
		opts = []grpc.ServerOption{grpc.Creds(creds)}
		s.tlsCheck = tlscheck.New(s.Config.TlsCertFile, s.Config.TlsKeyFile, time.Hour*24*16)
	}

	h := health.New(s, s.Storage)
	grpcServer := grpc.NewServer(opts...)
	catalogGrpc := &catalogGrpcServer{
		server: s,
	}
	pb.RegisterCatalogServiceServer(grpcServer, catalogGrpc)
	grpc_health_v1.RegisterHealthServer(grpcServer, h)

	go http.ListenAndServe(s.Config.GetHealthPortString(), h)

	log.Infof("server.go: Binding %s for grpc", grpcPort)
	//Serve
	return grpcServer.Serve(lis)
}
Пример #2
0
func (s *Server) ListenGRPC() error {
	grpcPort := s.Config.GetGrpcPortString()
	//Listen
	lis, err := net.Listen("tcp", grpcPort)
	if err != nil {
		return fmt.Errorf("server.go: failed to listen, %v", err)
	}

	var opts []grpc.ServerOption
	if s.Config.TlsCertFile != "" && s.Config.TlsKeyFile != "" {
		creds, err := credentials.NewServerTLSFromFile(s.Config.TlsCertFile, s.Config.TlsKeyFile)
		if err != nil {
			return fmt.Errorf("server.go: Failed to generate credentials %v", err)
		}
		opts = []grpc.ServerOption{grpc.Creds(creds)}
	}
	s.checker = health.New(s, s.DB)
	grpcServer := grpc.NewServer(opts...)
	man := newABManager(s)
	s.ab = man

	ab := &abTestServer{m: man, s: s}
	registryGrpc := &RegistryServer{server: s}
	otsimopb.RegisterRegistryServiceServer(grpcServer, registryGrpc)
	otsimopb.RegisterABTestServer(grpcServer, ab)

	grpc_health_v1.RegisterHealthServer(grpcServer, s.checker)

	log.Infof("server.go: Binding %s for grpc", grpcPort)
	return grpcServer.Serve(lis)
}
Пример #3
0
func (server *Server) ListenAndServe() error {
	port := server.Config.GetPortString()

	//Listen
	lis, err := net.Listen("tcp", port)
	if err != nil {
		return err
	}

	grpcServer := grpc.NewServer()
	pb.RegisterNotificationServiceServer(grpcServer, server)
	hs := health.New(server)
	grpc_health_v1.RegisterHealthServer(grpcServer, hs)
	go http.ListenAndServe(server.Config.GetHealthPortString(), hs)
	log.Infoln("server.go: Listening", port)
	//Serve
	return grpcServer.Serve(lis)
}
Пример #4
0
func (s *Server) ListenGRPC() error {
	grpcPort := s.Config.GetGrpcPortString()
	//Listen
	lis, err := net.Listen("tcp", grpcPort)
	if err != nil {
		return fmt.Errorf("server.go: failed to listen, %v", err)
	}
	hs := health.New()
	var opts []grpc.ServerOption
	if s.Config.TlsCertFile != "" && s.Config.TlsKeyFile != "" {
		creds, err := credentials.NewServerTLSFromFile(s.Config.TlsCertFile, s.Config.TlsKeyFile)
		if err != nil {
			return fmt.Errorf("server.go: Failed to generate credentials %v", err)
		}
		opts = []grpc.ServerOption{grpc.Creds(creds)}
		s.tlsCheck = tls.New(s.Config.TlsCertFile, s.Config.TlsKeyFile, time.Hour*24*19)
		hs.Checks = append(hs.Checks, s.tlsCheck)
	}
	grpcServer := grpc.NewServer(opts...)

	watchGrpc := &watchGrpcServer{
		server: s,
	}

	pb.RegisterWatchServiceServer(grpcServer, watchGrpc)
	grpc_health_v1.RegisterHealthServer(grpcServer, hs)

	if !s.Config.NoRedis {
		cl, err := NewRedisClient(s.Config)
		if err != nil {
			return fmt.Errorf("failed to create redis client, %v", err)
		}
		s.Redis = cl
		hs.Checks = append(hs.Checks, s.Redis)
	}

	log.Infof("server.go: Binding %s for grpc and :%d for health", grpcPort, s.Config.HealthPort)
	go http.ListenAndServe(s.Config.GetHealthPortString(), hs)
	go h.run()
	return grpcServer.Serve(lis)
}