Documentation ¶
Index ¶
- Constants
- Variables
- func CallHeader(ctx context.Context) map[string]string
- func MakeReplyFunc[T any](ctx context.Context) (replay func(T, error) error)
- func Reply(ctx context.Context, rep interface{}, repErr error) error
- type CallOption
- type CallOptions
- type Client
- type ClientInterface
- type ClientOption
- type ClientOptions
- type Encoder
- type Handler
- type Interceptor
- type Invoker
- type MethodDesc
- type Server
- type ServerInterface
- type ServerOption
- type ServerOptions
- type Service
- type ServiceDesc
- type ServiceInterface
- type ServiceOption
- type ServiceOptions
- type ServiceRegistrar
Constants ¶
const (
SupportVersion_0_7_0 = true
)
const (
Version = "v0.7.0"
)
Variables ¶
var ( ErrHeaderFormat = errors.New("natsrpc: header format error") ErrDuplicateService = errors.New("natsrpc: duplicate service") ErrNoMethod = errors.New("natsrpc: no method") ErrNoMeta = errors.New("natsrpc: no meta data") ErrEmptyReply = errors.New("natsrpc: reply is empty") // ErrReplyLater // It's not an error, when you want to reply message later, then return this. ErrReplyLater = errors.New("natsrpc: reply later") )
var DefaultClientOptions = ClientOptions{ // contains filtered or unexported fields }
DefaultClientOptions 默认client选项
var DefaultServerOptions = ServerOptions{ // contains filtered or unexported fields }
DefaultServerOptions 默认server选项
var DefaultServiceOptions = ServiceOptions{ // contains filtered or unexported fields }
DefaultServiceOptions 默认service选项
var ( // optional bool publish = 2360; E_Publish = &file_natsrpc_proto_extTypes[0] // true表示广播(不需要返回值), false表示request(需要返回值) )
Extension fields to descriptorpb.MethodOptions.
var File_natsrpc_proto protoreflect.FileDescriptor
Functions ¶
func MakeReplyFunc ¶
MakeReplyFunc 构造一个延迟返回函数
Types ¶
type CallOptions ¶
type CallOptions struct {
// contains filtered or unexported fields
}
CallOptions 调用选项
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client RPC client
type ClientInterface ¶
type ClientInterface interface { // Publish 发布 Publish(ctx context.Context, service, method string, req interface{}, opt ...CallOption) error // Request 请求 Request(ctx context.Context, service, method string, req interface{}, rep interface{}, opt ...CallOption) error }
ClientInterface 客户端接口
type ClientOption ¶
type ClientOption func(options *ClientOptions)
func WithClientID ¶
func WithClientID(id string) ClientOption
WithClientID call id(不会覆盖clientOptions.id,只是用来标识这次调用)
func WithClientNamespace ¶
func WithClientNamespace(namespace string) ClientOption
WithClientNamespace 空间集群
type ClientOptions ¶
type ClientOptions struct {
// contains filtered or unexported fields
}
ClientOptions client 选项
type Encoder ¶
type Encoder interface { // Encode 编码 Encode(v interface{}) ([]byte, error) // Decode 解码 Decode(data []byte, vPtr interface{}) error }
Encoder 编码器
type Interceptor ¶
type MethodDesc ¶
type MethodDesc struct { MethodName string // 方法名 Handler Handler // 方法处理函数 IsPublish bool // 是否发布 RequestType reflect.Type // 请求类型 }
MethodDesc 方法描述
type Server ¶
type Server struct { Encoder // contains filtered or unexported fields }
Server RPC server
func NewServer ¶
func NewServer(conn *nats.Conn, option ...ServerOption) (*Server, error)
NewServer 构造器
func (*Server) Register ¶
func (s *Server) Register(sd ServiceDesc, val interface{}, opts ...ServiceOption) (ServiceInterface, error)
Register 注册服务
type ServerInterface ¶
type ServerOption ¶
type ServerOption func(options *ServerOptions)
ServerOption server option
func WithErrorHandler ¶
func WithErrorHandler(h func(interface{})) ServerOption
WithErrorHandler error handler
func WithServerRecovery ¶
func WithServerRecovery(h func(interface{})) ServerOption
WithServerRecovery recover handler
type ServerOptions ¶
type ServerOptions struct {
// contains filtered or unexported fields
}
ServerOptions server 选项
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 服务
func NewService ¶
func NewService(server ServerInterface, sd ServiceDesc, i interface{}, options ServiceOptions) (*Service, error)
NewService 创建服务
type ServiceDesc ¶
type ServiceDesc struct { ServiceName string // 服务名 Methods []MethodDesc // 方法列表 Metadata string // 元数据 }
ServiceDesc 服务描述
type ServiceInterface ¶
ServiceInterface 服务
type ServiceOption ¶
type ServiceOption func(options *ServiceOptions)
ServiceOption Service option
func WithServiceInterceptor ¶
func WithServiceInterceptor(i Interceptor) ServiceOption
WithServiceInterceptor handler 拦截器
func WithServiceNamespace ¶
func WithServiceNamespace(namespace string) ServiceOption
WithServiceNamespace 空间集群
func WithServiceSingleGoroutine ¶
func WithServiceSingleGoroutine() ServiceOption
WithServiceSingleGoroutine 单协程,不并发handle,给那种消息需要顺序处理的情况
func WithServiceTimeout ¶
func WithServiceTimeout(timeout time.Duration) ServiceOption
WithServiceTimeout 超时时间
type ServiceOptions ¶
type ServiceOptions struct {
// contains filtered or unexported fields
}
ServiceOptions Service 选项
type ServiceRegistrar ¶
type ServiceRegistrar interface { // Register 注册 Register(sd ServiceDesc, svc any, opt ...ServiceOption) (ServiceInterface, error) }
ServiceRegistrar 注册服务