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 CallHeader ¶ added in v0.6.0
CallHeader 获得call Header
func MakeReplyFunc ¶ added in v0.6.0
MakeReplyFunc 构造一个延迟返回函数
Types ¶
type CallOption ¶ added in v0.0.5
type CallOption func(options *CallOptions)
CallOption call option
func WithCallHeader ¶ added in v0.1.0
func WithCallHeader(hd map[string]string) CallOption
WithCallHeader header
type CallOptions ¶ added in v0.1.0
type CallOptions struct {
// contains filtered or unexported fields
}
CallOptions 调用选项
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client RPC client
type ClientInterface ¶ added in v0.7.0
type ClientInterface interface { // Publish 发布 Publish(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 ¶ added in v0.0.5
type ClientOption func(options *ClientOptions)
func WithClientEncoder ¶ added in v0.6.0
func WithClientEncoder(encoder Encoder) ClientOption
WithClientEncoder 编码
func WithClientID ¶ added in v0.0.5
func WithClientID(id string) ClientOption
WithClientID call id(不会覆盖clientOptions.id,只是用来标识这次调用)
func WithClientNamespace ¶ added in v0.0.5
func WithClientNamespace(namespace string) ClientOption
WithClientNamespace 空间集群
type ClientOptions ¶ added in v0.6.0
type ClientOptions struct {
// contains filtered or unexported fields
}
ClientOptions client 选项
type Encoder ¶ added in v0.6.0
type Encoder interface { // Encode 编码 Encode(v interface{}) ([]byte, error) // Decode 解码 Decode(data []byte, vPtr interface{}) error }
Encoder 编码器
type Interceptor ¶ added in v0.6.0
type MethodDesc ¶ added in v0.6.0
type MethodDesc struct { MethodName string // 方法名 Handler Handler // 方法处理函数 IsPublish bool // 是否发布 RequestType reflect.Type // 请求类型 }
MethodDesc 方法描述
func (MethodDesc) NewRequest ¶ added in v0.6.0
func (md MethodDesc) NewRequest() any
NewRequest 创建请求 后面优化成静态的
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 注册服务
func (*Server) UnSubscribeAll ¶ added in v0.6.0
UnSubscribeAll 取消所有订阅
type ServerInterface ¶ added in v0.7.0
type ServerOption ¶ added in v0.0.5
type ServerOption func(options *ServerOptions)
ServerOption server option
func WithErrorHandler ¶ added in v0.1.0
func WithErrorHandler(h func(interface{})) ServerOption
WithErrorHandler error handler
func WithServerEncoder ¶ added in v0.6.0
func WithServerEncoder(encoder Encoder) ServerOption
WithServerEncoder 编码
func WithServerRecovery ¶ added in v0.0.5
func WithServerRecovery(h func(interface{})) ServerOption
WithServerRecovery recover handler
type ServerOptions ¶ added in v0.6.0
type ServerOptions struct {
// contains filtered or unexported fields
}
ServerOptions server 选项
type Service ¶ added in v0.0.2
type Service struct {
// contains filtered or unexported fields
}
Service 服务
func NewService ¶ added in v0.6.0
func NewService(server ServerInterface, sd ServiceDesc, i interface{}, options ServiceOptions) (*Service, error)
NewService 创建服务
type ServiceDesc ¶ added in v0.6.0
type ServiceDesc struct { ServiceName string // 服务名 Methods []MethodDesc // 方法列表 Metadata string // 元数据 }
ServiceDesc 服务描述
type ServiceInterface ¶ added in v0.7.0
ServiceInterface 服务
type ServiceOption ¶ added in v0.0.5
type ServiceOption func(options *ServiceOptions)
ServiceOption Service option
func WithServiceInterceptor ¶ added in v0.6.0
func WithServiceInterceptor(i Interceptor) ServiceOption
WithServiceInterceptor handler 拦截器
func WithServiceNamespace ¶ added in v0.0.5
func WithServiceNamespace(namespace string) ServiceOption
WithServiceNamespace 空间集群
func WithServiceSingleGoroutine ¶ added in v0.6.0
func WithServiceSingleGoroutine() ServiceOption
WithServiceSingleGoroutine 单协程,不并发handle,给那种消息需要顺序处理的情况
func WithServiceTimeout ¶ added in v0.0.5
func WithServiceTimeout(timeout time.Duration) ServiceOption
WithServiceTimeout 超时时间
type ServiceOptions ¶ added in v0.6.0
type ServiceOptions struct {
// contains filtered or unexported fields
}
ServiceOptions Service 选项
type ServiceRegistrar ¶ added in v0.6.0
type ServiceRegistrar interface { // Register 注册 Register(sd ServiceDesc, svc any, opt ...ServiceOption) (ServiceInterface, error) }
ServiceRegistrar 注册服务