grpc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	Response interface{}
	Error    error
}

CallResult gRPC调用结果

type Client

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

Client gRPC客户端

func NewClient

func NewClient(target string) (*Client, error)

NewClient 创建新的gRPC客户端

func NewClientWithOptions

func NewClientWithOptions(target string, opts ...grpc.DialOption) (*Client, error)

NewClientWithOptions 使用自定义选项创建gRPC客户端

func (*Client) Call

func (c *Client) Call(method string, request interface{}, response interface{}, opts ...grpc.CallOption) error

Call 调用gRPC方法

func (*Client) CallWithContext

func (c *Client) CallWithContext(ctx context.Context, method string, request interface{}, response interface{}, opts ...grpc.CallOption) error

CallWithContext 使用上下文调用gRPC方法

func (*Client) CallWithMetadata

func (c *Client) CallWithMetadata(ctx context.Context, method string, request interface{}, response interface{}, md map[string]string, opts ...grpc.CallOption) error

CallWithMetadata 使用元数据调用gRPC方法

func (*Client) CallWithTimeout

func (c *Client) CallWithTimeout(method string, request interface{}, response interface{}, timeout time.Duration, opts ...grpc.CallOption) error

CallWithTimeout 使用超时调用gRPC方法

func (*Client) Close

func (c *Client) Close() error

Close 关闭gRPC连接

func (*Client) GetConnection

func (c *Client) GetConnection() *grpc.ClientConn

GetConnection 获取gRPC连接

func (*Client) GetState

func (c *Client) GetState() string

GetState 获取连接状态

func (*Client) GetTarget

func (c *Client) GetTarget() string

GetTarget 获取目标地址

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected 检查是否已连接

func (*Client) Ping

func (c *Client) Ping() error

Ping 测试连接

func (*Client) Reconnect

func (c *Client) Reconnect() error

Reconnect 重新连接

func (*Client) StreamCall

func (c *Client) StreamCall(method string, request interface{}, opts ...grpc.CallOption) (grpc.ClientStream, error)

StreamCall 流式调用gRPC方法

func (*Client) StreamCallWithContext

func (c *Client) StreamCallWithContext(ctx context.Context, method string, request interface{}, opts ...grpc.CallOption) (grpc.ClientStream, error)

StreamCallWithContext 使用上下文进行流式调用

func (*Client) WithBlock

func (c *Client) WithBlock() *Client

WithBlock 设置阻塞连接

func (*Client) WithDefaultCallOptions

func (c *Client) WithDefaultCallOptions(opts ...grpc.CallOption) *Client

WithDefaultCallOptions 设置默认调用选项

func (*Client) WithInsecure

func (c *Client) WithInsecure() *Client

WithInsecure 设置不安全连接

func (*Client) WithTimeout

func (c *Client) WithTimeout(timeout time.Duration) *Client

WithTimeout 设置连接超时

func (*Client) WithUserAgent

func (c *Client) WithUserAgent(userAgent string) *Client

WithUserAgent 设置用户代理

type Pool

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

Pool gRPC连接池

func NewPool

func NewPool(maxSize int) *Pool

NewPool 创建新的gRPC连接池

func (*Pool) Close

func (p *Pool) Close() error

Close 关闭连接池

func (*Pool) Get

func (p *Pool) Get(target string) (*Client, error)

Get 从连接池获取客户端

func (*Pool) Remove

func (p *Pool) Remove(target string) error

Remove 移除连接

func (*Pool) Size

func (p *Pool) Size() int

Size 获取连接池大小

Jump to

Keyboard shortcuts

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