Documentation ¶
Index ¶
- type Client
- type ClientConfig
- type GrpcRegister
- type GrpcServer
- type HandlerFunc
- type Middleware
- type Options
- type Server
- func (s *Server) Close() error
- func (s *Server) GetAllServiceDesc() []*common.ServiceOpDesc
- func (s *Server) GetMethodDesc(serviceName, methodName string) (*common.ServiceOpDesc, *common.MethodOpDesc)
- func (s *Server) GetServiceDesc(service string) *common.ServiceOpDesc
- func (s *Server) RegisterServiceDesc(op *common.ServiceOpDesc)
- func (s *Server) Run(ctx context.T) error
- type WebApiRegister
- type WebServer
- func (s *WebServer) AddMiddleware(m ...Middleware)
- func (s *WebServer) Close() error
- func (s *WebServer) Ping(w http.ResponseWriter, req *http.Request)
- func (s *WebServer) Serve(ctx context.T, ln net.Listener) error
- func (s *WebServer) WebApiDecode(ctx *context.T, req *http.Request, arg interface{}) error
- func (s *WebServer) WebApiHandleResp(ctx *context.T, w http.ResponseWriter, resp interface{}, err error)
- func (s *WebServer) WebApiRegister(method string, ...)
- func (s *WebServer) WebApiRegisterMethod(serviceName, methodName string, ...) bool
- func (s *WebServer) WebapiHandlerFunc(path string, handler HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { GRPC *grpc.ClientConn // contains filtered or unexported fields }
GRPC Client
type ClientConfig ¶
type ClientConfig struct { Balancer balancer.Balancer Name string Desc *common.ServiceOpDesc // 这里拿到的是每个服务的 proto 文件中的配置信息 }
type GrpcRegister ¶
type GrpcRegister interface { GetServer() *grpc.Server // 获取grpc's server RegisterService(name string, methods []string) // 注册服务及其提供的接口方法 }
GRPC 提供的注册
type GrpcServer ¶
type GrpcServer struct {
// contains filtered or unexported fields
}
GRPC 服务主体
func (*GrpcServer) Close ¶
func (s *GrpcServer) Close() error
func (*GrpcServer) GetServer ¶
func (s *GrpcServer) GetServer() *grpc.Server
func (*GrpcServer) GrpcAddInterceptor ¶
func (s *GrpcServer) GrpcAddInterceptor(i grpc.UnaryServerInterceptor)
提供服务端拦截器 添加
func (*GrpcServer) RegisterService ¶
func (s *GrpcServer) RegisterService(name string, methods []string)
往GRPC服务中添加待注册的service
type HandlerFunc ¶
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
中间件 - 本质就是一个func,将函数保存起来等到需要的时候对入参进行处理
type Options ¶
type Options interface { GetServiceDesc(serviceName string) *common.ServiceOpDesc GetMethodDesc(service, method string) (*common.ServiceOpDesc, *common.MethodOpDesc) GetAllServiceDesc() []*common.ServiceOpDesc }
type Server ¶
type Server struct { Port int // 端口号 GrpcServer WebServer // contains filtered or unexported fields }
func (*Server) GetAllServiceDesc ¶
func (s *Server) GetAllServiceDesc() []*common.ServiceOpDesc
func (*Server) GetMethodDesc ¶
func (s *Server) GetMethodDesc(serviceName, methodName string) (*common.ServiceOpDesc, *common.MethodOpDesc)
func (*Server) GetServiceDesc ¶
func (s *Server) GetServiceDesc(service string) *common.ServiceOpDesc
func (*Server) RegisterServiceDesc ¶
func (s *Server) RegisterServiceDesc(op *common.ServiceOpDesc)
通过调用Register将服务的Desc注入进来
type WebApiRegister ¶
type WebApiRegister interface { WebApiRegister(method string, handler func(ctx *context.T, w http.ResponseWriter, req *http.Request)) WebApiRegisterMethod(service, method string, handler func(ctx *context.T, w http.ResponseWriter, req *http.Request)) bool // 解码 WebApiDecode(ctx *context.T, req *http.Request, arg interface{}) error WebApiHandleResp(*context.T, http.ResponseWriter, interface{}, error) }
WebApi 注册
type WebServer ¶
type WebServer struct {
// contains filtered or unexported fields
}
WEB 服务 + 利用http的路由保存method,以供提供WebApi服务
func (*WebServer) AddMiddleware ¶
func (s *WebServer) AddMiddleware(m ...Middleware)
func (*WebServer) WebApiDecode ¶
下面👇两个方法是涉及到 grpc 方法 《=》 webapi 相互转化问题
func (*WebServer) WebApiHandleResp ¶
func (s *WebServer) WebApiHandleResp(ctx *context.T, w http.ResponseWriter, resp interface{}, err error)
将GRPC结果再转换为HTTP的返回结果
func (*WebServer) WebApiRegister ¶
func (s *WebServer) WebApiRegister(method string, handler func(ctx *context.T, w http.ResponseWriter, req *http.Request))
注册方法
func (*WebServer) WebApiRegisterMethod ¶
func (*WebServer) WebapiHandlerFunc ¶
func (s *WebServer) WebapiHandlerFunc(path string, handler HandlerFunc)
注册接口到路由中 - 具体实现
Click to show internal directories.
Click to hide internal directories.