Documentation
¶
Overview ¶
Package rpc 提供标准化的 RPC 调用封装与响应处理工具。
Index ¶
- Constants
- Variables
- func NewRemoteInvokeServiceContext(bootstrapConf conf.BootstrapConf) context.Context
- func NewRemoteServiceGrpcClient(bootstrapConf conf.BootstrapConf) (*grpc.ClientConn, error)
- func ParseMetaKey(md metadata.MD, key string) (string, error)
- func SetRemoteInvokeServiceContext(ctx context.Context, bootstrapConf conf.BootstrapConf) context.Context
- type UserContextMeta
Constants ¶
View Source
const MetaKeyParseErrorFormat = "%s 解析失败"
MetaKeyParseErrorFormat 用于构造元信息缺失/解析失败的错误文本。
Variables ¶
View Source
var ( // ErrRemoteResponseIsNil 表示远程调用返回的响应对象为空。 ErrRemoteResponseIsNil = errors.New("远程响应为空") // ErrRemoteCallFailed 表示远程调用失败但未返回可读错误信息。 ErrRemoteCallFailed = errors.New("远程调用失败") )
Functions ¶
func NewRemoteInvokeServiceContext ¶ added in v0.9.7
func NewRemoteInvokeServiceContext(bootstrapConf conf.BootstrapConf) context.Context
NewRemoteInvokeServiceContext 初始化远程调用服务上下文, 适用于服务自身(无其他用户特征)调用其他服务时,可基于此上下文进行设置上下文
func NewRemoteServiceGrpcClient ¶ added in v0.9.8
func NewRemoteServiceGrpcClient(bootstrapConf conf.BootstrapConf) (*grpc.ClientConn, error)
func ParseMetaKey ¶
ParseMetaKey 解析元信息 key。
func SetRemoteInvokeServiceContext ¶ added in v1.0.9
func SetRemoteInvokeServiceContext(ctx context.Context, bootstrapConf conf.BootstrapConf) context.Context
SetRemoteInvokeServiceContext 设置远程调用上下文,基于当前上下文进行设置服务自身的信息,并设置链路追踪,一般是将其封装成中间件使用
Types ¶
type UserContextMeta ¶
type UserContextMeta struct {
Session string `json:"session"`
ClientIp string `json:"client_ip"`
UserId string `json:"user_id"`
AppId string `json:"app_id"`
TenantId string `json:"tenant_id"`
RoleIds []string `json:"role_ids"`
OrgIds []string `json:"org_ids"`
}
UserContextMeta 表示用户元信息
func ParseUserContextMeta ¶
func ParseUserContextMeta(md metadata.MD) (raw *UserContextMeta, err error)
ParseUserContextMeta 解析用户上下文元信息。
Click to show internal directories.
Click to hide internal directories.