server

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRunner

func NewRunner(grpcSrv *grpc.Server, lis net.Listener) *runner

Types

type Config

type Config struct {
	// 服务名称,命名空间内唯一的调用标识
	ServerName string
	// 服务监听的端口
	Port int
}

Config 是gRPC server的配置

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

Server is the framework's server side instance, it contains the GrpcServer, interceptor and interceptors. Create an instance of Server, by using NewServer().

func NewServer

func NewServer(conf *Config, o ...grpc.ServerOption) (s *Server)

NewServer create a grpc server instance

func (*Server) GrpcServer

func (s *Server) GrpcServer() *grpc.Server

func (*Server) HealthService

func (s *Server) HealthService() *health.Server

func (*Server) OnStop

func (s *Server) OnStop(hook func(ctx context.Context) error)

OnStop add stop hook to grpc server when server got terminating signal 默认传入一个10s的timeout的context

func (*Server) Start

func (s *Server) Start() error

Start create a tcp listener and start goroutine for serving each incoming request. Start will block until term signal is received.

func (*Server) Use

func (s *Server) Use(interceptors ...grpc.UnaryServerInterceptor) *Server

Use attachs a global inteceptor to the server. For example, this is the right place for a rate limiter or error management inteceptor. This function is not concurrency safe.

func (*Server) UseStream

func (s *Server) UseStream(interceptors ...grpc.StreamServerInterceptor) *Server

UseStream attachs a global inteceptor to the server. For example, this is the right place for a rate limiter or error management inteceptor. This function is not concurrency safe.

type WrappedServerStream

type WrappedServerStream struct {
	grpc.ServerStream
	// WrappedContext is the wrapper's own Context. You can assign it.
	WrappedContext context.Context
}

WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.

func WrapServerStream

func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*WrappedServerStream) Context

func (w *WrappedServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL