rpc1

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultUnaryInterceptor grpc.UnaryServerInterceptor = func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
	return UnaryInterceptorWithLogPrefix(ut2.RandomString(10), false, ctx, req, info, handler)
}

Functions

func Err

func Err(s any) error

func GetErrorCode

func GetErrorCode(err error) int

func GetErrorMessage

func GetErrorMessage(err error) string

获取错误消息。逻辑错误不显示错误码。

func RoundRobin

func RoundRobin() grpc.DialOption

grpc 内置 负载均衡器,客户端随机调用多个服务端

func UnaryInterceptorWithLogPrefix

func UnaryInterceptorWithLogPrefix(logpfx string, skipLogResp bool, ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func UseCodec

func UseCodec(codec encoding.Codec) grpc.DialOption

客户端添加到DialOption中,则默认使用指定协议传输

Types

type ClientManager

type ClientManager struct {
	// contains filtered or unexported fields
}

func NewClientManager

func NewClientManager(d resolver.Builder) *ClientManager

func (*ClientManager) Close

func (gx *ClientManager) Close()

func (*ClientManager) GetClient

func (gx *ClientManager) GetClient(serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

type DescAndImpl

type DescAndImpl struct {
	Desc *grpc.ServiceDesc
	Impl any
}

type JsonBytesCodec

type JsonBytesCodec struct{}

直接转发无需解析

func (JsonBytesCodec) Marshal

func (c JsonBytesCodec) Marshal(v interface{}) ([]byte, error)

func (JsonBytesCodec) Name

func (c JsonBytesCodec) Name() string

func (JsonBytesCodec) Unmarshal

func (c JsonBytesCodec) Unmarshal(data []byte, v interface{}) error

type JsonCodec

type JsonCodec struct{}

func (JsonCodec) Marshal

func (c JsonCodec) Marshal(v interface{}) ([]byte, error)

func (JsonCodec) Name

func (c JsonCodec) Name() string

func (JsonCodec) Unmarshal

func (c JsonCodec) Unmarshal(data []byte, v interface{}) error

type Server

type Server struct {
	*grpc.Server

	Config         *ServerOption
	Register       discovery.Register
	PortProvider   discovery.PortProvider
	ServiceDescMap ut2.IMap[string, *DescAndImpl]
}

func (*Server) Close

func (s *Server) Close()

func (*Server) RegisterService

func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl interface{})

func (*Server) Serve

func (gx *Server) Serve() error

type ServerOption

type ServerOption struct {
	Name             string // [必填]本服务名称
	Host             string // 用于给别人调用本服务的地址,会注册到注册中心,默认="127.0.0.1"
	UnaryInterceptor grpc.UnaryServerInterceptor
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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