Documentation ¶
Index ¶
- Variables
- func Err(s any) error
- func GetErrorCode(err error) int
- func GetErrorMessage(err error) string
- func RoundRobin() grpc.DialOption
- func UnaryInterceptorWithLogPrefix(logpfx string, skipLogResp bool, ctx context.Context, req interface{}, ...) (resp interface{}, err error)
- func UseCodec(codec encoding.Codec) grpc.DialOption
- type ClientManager
- type DescAndImpl
- type JsonBytesCodec
- type JsonCodec
- type Server
- type ServerOption
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 GetErrorCode ¶
func UnaryInterceptorWithLogPrefix ¶
func UnaryInterceptorWithLogPrefix(logpfx string, skipLogResp bool, ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
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 Server ¶
type Server struct { *grpc.Server Config *ServerOption Register discovery.Register PortProvider discovery.PortProvider ServiceDescMap ut2.IMap[string, *DescAndImpl] }
func NewServer ¶
func NewServer(cfg *ServerOption, p discovery.PortProvider, r discovery.Register) *Server
func (*Server) RegisterService ¶
func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl interface{})
type ServerOption ¶
type ServerOption struct { Name string // [必填]本服务名称 Host string // 用于给别人调用本服务的地址,会注册到注册中心,默认="127.0.0.1" UnaryInterceptor grpc.UnaryServerInterceptor }
Click to show internal directories.
Click to hide internal directories.