• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang grpc.Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中google/golang.org/grpc.Server的典型用法代码示例。如果您正苦于以下问题:Golang Server类的具体用法?Golang Server怎么用?Golang Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Server类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setUpSignerClient

func setUpSignerClient(t *testing.T, grpcServer *grpc.Server) (*client.NotarySigner, *grpc.ClientConn, func()) {
	socketFile, err := ioutil.TempFile("", "notary-grpc-test")
	require.NoError(t, err)
	socketFile.Close()
	os.Remove(socketFile.Name())

	lis, err := net.Listen("unix", socketFile.Name())
	require.NoError(t, err, "unable to open socket to listen")

	go grpcServer.Serve(lis)

	// client setup
	clientConn, err := grpc.Dial(socketFile.Name(), grpc.WithInsecure(), grpc.WithDialer(socketDialer))
	require.NoError(t, err, "unable to connect to socket as a GRPC client")

	signerClient := client.NewNotarySigner(clientConn)

	cleanup := func() {
		clientConn.Close()
		grpcServer.Stop()
		os.Remove(socketFile.Name())
	}

	return signerClient, clientConn, cleanup
}
开发者ID:jfrazelle,项目名称:notary,代码行数:25,代码来源:rpc_and_client_test.go


示例2: serveGRPC

func serveGRPC(server *grpc.Server, l net.Listener) {
	defer l.Close()
	if err := server.Serve(l); err != nil {
		l.Close()
		logrus.WithError(err).Fatal("containerd: GRPC server failure")
	}
}
开发者ID:docker,项目名称:containerd,代码行数:7,代码来源:main.go


示例3: Register

// PreregisterServices takes a gRPC server and pre-initializes all counters to 0.
// This allows for easier monitoring in Prometheus (no missing metrics), and should be called *after* all services have
// been registered with the server.
func Register(server *grpc.Server) {
	serviceInfo := server.GetServiceInfo()
	for serviceName, info := range serviceInfo {
		for _, mInfo := range info.Methods {
			preRegisterMethod(serviceName, &mInfo)
		}
	}
}
开发者ID:pulcy,项目名称:vault-monkey,代码行数:11,代码来源:server.go


示例4: startGRPC

func startGRPC(srv *grpc.Server) {
	l, err := net.Listen("tcp", *grpcListeningAddr)
	if err != nil {
		log.Fatalf("Error listening on GRPC address %q: %v", *grpcListeningAddr, err)
	}
	log.Printf("GRPC server listening on %s", l.Addr())
	log.Fatal(srv.Serve(l))
}
开发者ID:hunteras,项目名称:kythe,代码行数:8,代码来源:http_server.go


示例5: GRPCHandlerFunc

// GRPCHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
// connections or otherHandler otherwise.
func GRPCHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if IsGRPCRequest(r) {
			grpcServer.ServeHTTP(w, r)
		} else {
			otherHandler.ServeHTTP(w, r)
		}
	})
}
开发者ID:liugangnhm,项目名称:cockroach,代码行数:11,代码来源:grpc_util.go


示例6: grpcHandlerFunc

// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
// connections or otherHandler otherwise. Copied from cockroachdb.
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
			grpcServer.ServeHTTP(w, r)
		} else {
			otherHandler.ServeHTTP(w, r)
		}
	})
}
开发者ID:cherrybob,项目名称:etcd,代码行数:11,代码来源:serve.go


示例7: GRPCHandlerFunc

// GRPCHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
// connections or otherHandler otherwise.
func GRPCHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// TODO(tamird): point to merged gRPC code rather than a PR.
		// This is a partial recreation of gRPC's internal checks https://github.com/grpc/grpc-go/pull/514/files#diff-95e9a25b738459a2d3030e1e6fa2a718R61
		if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
			grpcServer.ServeHTTP(w, r)
		} else {
			otherHandler.ServeHTTP(w, r)
		}
	})
}
开发者ID:binlijin,项目名称:cockroach,代码行数:13,代码来源:grpc_util.go


示例8: waitShutdown

func waitShutdown(rpcSrv *grpc.Server, apiSrv *server.ApiServer) {
	sigCh := make(chan os.Signal)
	signal.Notify(sigCh, os.Interrupt, os.Kill)

	// Block until a signal is received or we got an error
	select {
	case signal := <-sigCh:
		log.Printf("Got signal %s, waiting for shutdown...", signal)
		rpcSrv.Stop()
		apiSrv.Shutdown()
		return
	}
}
开发者ID:hi-trust,项目名称:friendfeed,代码行数:13,代码来源:server.go


示例9: NewCommInstanceWithServer

// NewCommInstanceWithServer creates a comm instance that creates an underlying gRPC server
func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity api.PeerIdentityType, dialOpts ...grpc.DialOption) (Comm, error) {
	var ll net.Listener
	var s *grpc.Server
	var secOpt grpc.DialOption

	if len(dialOpts) == 0 {
		dialOpts = []grpc.DialOption{grpc.WithTimeout(dialTimeout)}
	}

	if port > 0 {
		s, ll, secOpt = createGRPCLayer(port)
		dialOpts = append(dialOpts, secOpt)
	}

	commInst := &commImpl{
		PKIID:             idMapper.GetPKIidOfCert(peerIdentity),
		idMapper:          idMapper,
		logger:            util.GetLogger(util.LOGGING_COMM_MODULE, fmt.Sprintf("%d", port)),
		peerIdentity:      peerIdentity,
		opts:              dialOpts,
		port:              port,
		lsnr:              ll,
		gSrv:              s,
		msgPublisher:      NewChannelDemultiplexer(),
		lock:              &sync.RWMutex{},
		deadEndpoints:     make(chan common.PKIidType, 100),
		stopping:          int32(0),
		exitChan:          make(chan struct{}, 1),
		subscriptions:     make([]chan ReceivedMessage, 0),
		blackListedPKIIDs: make([]common.PKIidType, 0),
	}
	commInst.connStore = newConnStore(commInst, commInst.logger)
	commInst.idMapper.Put(idMapper.GetPKIidOfCert(peerIdentity), peerIdentity)

	if port > 0 {
		go func() {
			commInst.stopWG.Add(1)
			defer commInst.stopWG.Done()
			s.Serve(ll)
		}()
		proto.RegisterGossipServer(s, commInst)
	}

	commInst.logger.SetLevel(logging.WARNING)

	return commInst, nil
}
开发者ID:kchristidis,项目名称:fabric,代码行数:48,代码来源:comm_impl.go


示例10: ListenAndServeGRPC

// ListenAndServeGRPC creates a listener and serves the specified grpc Server
// on it, closing the listener when signalled by the stopper.
func ListenAndServeGRPC(stopper *stop.Stopper, server *grpc.Server,
	addr net.Addr) (net.Listener, error) {
	ln, err := net.Listen(addr.Network(), addr.String())
	if err != nil {
		return ln, err
	}

	stopper.RunWorker(func() {
		<-stopper.ShouldDrain()
		server.Stop()
	})

	stopper.RunWorker(func() {
		FatalIfUnexpected(server.Serve(ln))
	})
	return ln, nil
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:19,代码来源:net.go


示例11: ListenAndServeGRPC

// ListenAndServeGRPC creates a listener and serves server on it, closing
// the listener when signalled by the stopper.
func ListenAndServeGRPC(stopper *stop.Stopper, server *grpc.Server, addr net.Addr, config *tls.Config) (net.Listener, error) {
	ln, err := util.Listen(addr, config)
	if err != nil {
		return nil, err
	}

	stopper.RunWorker(func() {
		if err := server.Serve(ln); err != nil && !util.IsClosedConnection(err) {
			log.Fatal(err)
		}
	})

	stopper.RunWorker(func() {
		<-stopper.ShouldDrain()
		if err := ln.Close(); err != nil {
			log.Fatal(err)
		}
	})

	return ln, nil
}
开发者ID:binlijin,项目名称:cockroach,代码行数:23,代码来源:grpc_util.go


示例12: RegisterDatastoreServer

func RegisterDatastoreServer(s *grpc.Server, srv DatastoreServer) {
	s.RegisterService(&_Datastore_serviceDesc, srv)
}
开发者ID:takbok,项目名称:shared-contacts-admin,代码行数:3,代码来源:datastore.pb.go


示例13: RegisterDeviceManagerServer

func RegisterDeviceManagerServer(s *grpc.Server, srv DeviceManagerServer) {
	s.RegisterService(&_DeviceManager_serviceDesc, srv)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:3,代码来源:device.pb.go


示例14: RegisterThrottlerServer

func RegisterThrottlerServer(s *grpc.Server, srv ThrottlerServer) {
	s.RegisterService(&_Throttler_serviceDesc, srv)
}
开发者ID:CowLeo,项目名称:vitess,代码行数:3,代码来源:throttlerservice.pb.go


示例15: RegisterPropServer

func RegisterPropServer(s *grpc.Server, srv PropServer) {
	s.RegisterService(&_Prop_serviceDesc, srv)
}
开发者ID:clawio,项目名称:service-localfsxattr-meta,代码行数:3,代码来源:propagator.pb.go


示例16: RegisterAutomationServer

func RegisterAutomationServer(s *grpc.Server, srv AutomationServer) {
	s.RegisterService(&_Automation_serviceDesc, srv)
}
开发者ID:littleyang,项目名称:vitess,代码行数:3,代码来源:automationservice.pb.go


示例17: RegisterEventsServer

func RegisterEventsServer(s *grpc.Server, srv EventsServer) {
	s.RegisterService(&_Events_serviceDesc, srv)
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:3,代码来源:events.pb.go


示例18: RegisterTxnSvcServer

func RegisterTxnSvcServer(s *grpc.Server, srv TxnSvcServer) {
	s.RegisterService(&_TxnSvc_serviceDesc, srv)
}
开发者ID:kshlm,项目名称:glusterd2,代码行数:3,代码来源:transaction-rpc.pb.go


示例19: RegisterMysqlCtlServer

func RegisterMysqlCtlServer(s *grpc.Server, srv MysqlCtlServer) {
	s.RegisterService(&_MysqlCtl_serviceDesc, srv)
}
开发者ID:aaijazi,项目名称:vitess,代码行数:3,代码来源:mysqlctl.pb.go


示例20: RegisterHealthServer

func RegisterHealthServer(s *grpc.Server, srv HealthServer) {
	s.RegisterService(&_Health_serviceDesc, srv)
}
开发者ID:sr,项目名称:pachyderm,代码行数:3,代码来源:health.pb.go



注:本文中的google/golang.org/grpc.Server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang grpc.ServerStream类代码示例发布时间:2022-05-28
下一篇:
Golang grpc.Codec类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap