本文整理汇总了Golang中google/golang.org/grpc.Server类的典型用法代码示例。如果您正苦于以下问题:Golang Server类的具体用法?Golang Server怎么用?Golang Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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")
}
}
示例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)
}
}
}
示例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))
}
示例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)
}
})
}
示例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)
}
})
}
示例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)
}
})
}
示例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
}
}
示例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
}
示例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
}
示例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
}
示例12: RegisterDatastoreServer
func RegisterDatastoreServer(s *grpc.Server, srv DatastoreServer) {
s.RegisterService(&_Datastore_serviceDesc, srv)
}
示例13: RegisterDeviceManagerServer
func RegisterDeviceManagerServer(s *grpc.Server, srv DeviceManagerServer) {
s.RegisterService(&_DeviceManager_serviceDesc, srv)
}
示例14: RegisterThrottlerServer
func RegisterThrottlerServer(s *grpc.Server, srv ThrottlerServer) {
s.RegisterService(&_Throttler_serviceDesc, srv)
}
示例15: RegisterPropServer
func RegisterPropServer(s *grpc.Server, srv PropServer) {
s.RegisterService(&_Prop_serviceDesc, srv)
}