Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClientContext ¶
func NewClientContext(ctx context.Context, tr Transporter) context.Context
NewClientContext 返回一个包含传输值的新上下文
func NewServerContext ¶
func NewServerContext(ctx context.Context, tr Transporter) context.Context
NewServerContext 返回一个包含传输值的新上下文
Types ¶
type EndpointProvider ¶
EndpointProvider 是用于注册的端点接口
type Header ¶
type Header interface {
// Get 获取指定 key 的值
Get(key string) string
// Set 设置指定 key 的值
Set(key string, value string)
// Add 添加指定 key 的值
Add(key string, value string)
// Keys 返回所有头部的键名
Keys() []string
// Values 返回指定 key 对应的所有值
Values(key string) []string
}
Header 是存储头部数据的接口
type Server ¶
type Server interface {
// Start 启动服务
Start(context.Context) error
// Stop 停止服务
Stop(context.Context) error
}
Server 是传输服务接口
type Transporter ¶
type Transporter interface {
// Kind 返回传输类型
// grpc 或 http
Kind() Kind
// Endpoint 返回服务端或客户端的端点
// 服务端传输: grpc://127.0.0.1:9000
// 客户端传输: discovery:///provider-demo
Endpoint() string
// Operation 返回服务的完整方法选择器(由 protobuf 生成)
// 示例: /helloworld.Greeter/SayHello
Operation() string
// RequestHeader 返回传输请求头部
// http: http.Header
// grpc: metadata.MD
RequestHeader() Header
// ReplyHeader 返回传输响应头部(仅适用于服务端传输)
// http: http.Header
// grpc: metadata.MD
ReplyHeader() Header
}
Transporter 是传输上下文值的接口
func FromClientContext ¶
func FromClientContext(ctx context.Context) (tr Transporter, ok bool)
FromClientContext 返回上下文中存储的传输值(如果有)
func FromServerContext ¶
func FromServerContext(ctx context.Context) (tr Transporter, ok bool)
FromServerContext 返回上下文中存储的传输值(如果有)
Click to show internal directories.
Click to hide internal directories.