xrpc

package
v0.7.15 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const TypeNode = "rpcs"

Variables

This section is empty.

Functions

func DeregisterClient added in v0.3.0

func DeregisterClient(name string)

Deregister 清理配置适配器

func DeregisterServer added in v0.3.0

func DeregisterServer(name string)

Deregister 清理配置适配器

func IsIpPortAddr added in v0.1.46

func IsIpPortAddr(addr string) (ip string, port int, ok bool)

func NewBuilder

func NewBuilder() container.StandardBuilder

func RegisterClient added in v0.3.0

func RegisterClient(resolver ClientResover)

Register 注册配置文件适配器

func RegisterServer added in v0.3.0

func RegisterServer(resolver ServerResolver)

Register 注册配置文件适配器

Types

type BidirectionalStreamClient added in v0.7.9

type BidirectionalStreamClient interface {
	ClientStreamRequest
	ServerStreamRequest
	CloseSend() error
}

BidirectionalStreamClient is an interface that represents a bidirectional stream client.

type BidirectionalStreamProcessor added in v0.7.9

type BidirectionalStreamProcessor func(BidirectionalStreamClient) error

BidirectionalStreamProcessor is a callback function that can be used to process a bidirectional stream.

type BidirectionalStreamRequest added in v0.7.9

type BidirectionalStreamRequest interface {
	ClientStreamRequest
	ServerStreamRequest
}

StreamRequest is an interface that represents a stream request.

type Body

type Body interface {
	GetStatus() int32
	GetHeader() map[string]string
	GetResult() []byte
}

func NewEmptyBody added in v0.7.9

func NewEmptyBody() Body

NewEmptyBody returns an empty body object.

type Client

type Client interface {
	//Swap 将当前请求参数作为RPC参数并发送RPC请求
	Swap(ctx context.Context, service string, opts ...RequestOption) (res Body, err error)

	//RequestByCtx RPC请求,可通过context撤销请求
	Request(ctx sctx.Context, service string, input interface{}, opts ...RequestOption) (res Body, err error)
}

type ClientResover added in v0.3.0

type ClientResover interface {
	Name() string
	Resolve(name string, setting config.Config) (Client, error)
}

ClientResover 定义配置文件转换方法

type ClientStreamChan added in v0.7.12

type ClientStreamChan interface {
	GetObject() <-chan any
}

ClientStreamChan 客户端流通道接口

type ClientStreamClient added in v0.7.9

type ClientStreamClient interface {
	Send(obj any) (err error)
}

ClientStreamClient is an interface that represents a stream client.

type ClientStreamObjects added in v0.7.12

type ClientStreamObjects interface {
	GetObjects() []any
}

ClientStreamObjects 客户端流对象接口

type ClientStreamProcessor added in v0.7.9

type ClientStreamProcessor func(ClientStreamClient) (err error)

ClientStreamProcessor is a callback function that can be used to process a stream client.

func BuildDefaultClientStreamProcess added in v0.7.12

func BuildDefaultClientStreamProcess(input any) (processor ClientStreamProcessor, err error)

BuildDefaultClientStreamProcess 构建默认的客户端流处理器

type ClientStreamRequest added in v0.7.9

type ClientStreamRequest interface {
	Recv(obj any, opts ...StreamRevcOption) (closed bool, err error)
}

ClientStreamRequest is an interface that represents a client stream request.

type Config added in v0.3.0

type Config struct {
	Addr           string        `json:"addr"`
	Proto          string        `json:"proto"`
	Status         engine.Status `json:"status"`
	MaxRecvMsgSize int           `json:"max_recv_msg_size"`
	MaxSendMsgSize int           `json:"max_send_msg_size"`
}

type DefaultProcessor added in v0.7.12

type DefaultProcessor struct{}

DefaultProcessor is a default implementation of StreamProcessor.

type Options

type Options struct {
	Header             xtypes.SMap // 请求头
	Method             string      // 请求方法
	Query              string      // 请求参数
	WaitForReady       bool        // 是否等待服务端响应
	MaxCallRecvMsgSize int         // 最大接收消息体大小,默认4M(maximum message size in bytes the client can receive)
	MaxCallSendMsgSize int         // 最大发送消息体大小,默认4M(maximum message size in bytes the client can send)
	StreamProcessor    any         // 是否使用流传输
}

type RequestOption

type RequestOption func(*Options)

func MaxCallRecvMsgSize added in v0.7.9

func MaxCallRecvMsgSize(size int) RequestOption

MaxCallRecvMsgSize

func MaxCallSendMsgSize added in v0.7.9

func MaxCallSendMsgSize(size int) RequestOption

MaxCallSendMsgSize

func WithContentType

func WithContentType(contentType string) RequestOption

WithContentType 设置请求内容类型

func WithHeaders

func WithHeaders(header map[string]string) RequestOption

WithHeaders 设置请求头

func WithMethod added in v0.5.1

func WithMethod(method string) RequestOption

WithMethod 设置请求方法

func WithQuery added in v0.5.1

func WithQuery(query string) RequestOption

WithQuery 设置请求参数

func WithSourceName added in v0.2.6

func WithSourceName() RequestOption

WithSourceName 设置来源服务名

func WithStreamDefaultProcessor added in v0.7.12

func WithStreamDefaultProcessor() RequestOption

WithStreamDefaultProcessor 设置使用默认流传输

func WithStreamProcessor added in v0.7.9

func WithStreamProcessor(processor any) RequestOption

WithStreamProcessor 设置使用流传输

func WithWaitForReady

func WithWaitForReady(waitForReady bool) RequestOption

WithWaitForReady 设置是否等待服务端响应

func WithXRequestID

func WithXRequestID(requestID string) RequestOption

WithXRequestID 设置请求ID

type Server added in v0.3.0

type Server interface {
	GetProto() string
	GetAddr() string
	Serve(ctx context.Context) (err error)
	Stop(ctx context.Context) error
}

func NewServer added in v0.3.0

func NewServer(proto string,
	router *engine.RouterGroup,
	cfg config.Config,
	opts ...engine.Option) (Server, error)

NewServer 根据适配器名称及参数返回配置处理器

type ServerResolver added in v0.7.1

type ServerResolver interface {
	Name() string
	Resolve(name string,
		router *engine.RouterGroup,
		cfg config.Config,
		opts ...engine.Option) (Server, error)
}

ServerResover 定义配置文件转换方法

type ServerStreamClient added in v0.7.9

type ServerStreamClient interface {
	Recv(obj any, opts ...StreamRevcOption) (closed bool, err error)
}

ServerStreamClient is an interface that represents a stream server.

type ServerStreamProcessor added in v0.7.9

type ServerStreamProcessor func(ServerStreamClient) (err error)

ServerStreamProcessor is a callback function that can be used to process a stream server.

type ServerStreamRequest added in v0.7.9

type ServerStreamRequest interface {
	Send(obj any) (err error)
}

ServerStreamRequest is an interface that represents a server stream request.

type StandardRPC

type StandardRPC interface {
	GetRPC(name string) (c Client)
}

type StreamRecvOptions added in v0.7.9

type StreamRecvOptions struct {
	Unmarshal StreamUnmarshaler
}

StreamRecvOptions is a struct that contains options for receiving messages.

type StreamRevcOption added in v0.7.9

type StreamRevcOption func(*StreamRecvOptions)

StreamRevcOption is a function that sets an option for receiving messages.

func WithStreamUnmarshal added in v0.7.9

func WithStreamUnmarshal(callback StreamUnmarshaler) StreamRevcOption

WithStreamUnmarshal sets the callback function to unmarshal a received message.

type StreamType added in v0.7.9

type StreamType int

StreamType is the type of stream.

const (
	UnknownStream       StreamType = 0
	BidirectionalStream StreamType = 1
	ClientStream        StreamType = 2
	ServerStream        StreamType = 3
)

type StreamUnmarshaler added in v0.7.9

type StreamUnmarshaler func([]byte, any) error

StreamUnmarshaler is a callback function that can be used to unmarshal a received message.

Jump to

Keyboard shortcuts

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