grpcclient

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package grpcclient 提供服务间 gRPC 调用的统一封装: discovery 寻址 + 连接池 + 超时 + tenant/trace metadata 注入 + 业务错误解包。

前置:调用前需先 discovery.Init(cfgDir)(解析各服务地址)与加载配置。

Index

Constants

View Source
const (
	IdentityhubSvr   = "identityhubsvr"
	TenantManagerSvr = "tenantmanagersvr"
)

后端服务名常量(discovery.json 的 key)。 集中维护:新增后端服务时在此加一个常量,供 grpcclient.Call(ctx, svcName, ...) 按服务名解析地址。

Variables

This section is empty.

Functions

func Call

func Call[T any](ctx context.Context, svcName string, fn func(ctx context.Context, conn *grpc.ClientConn) (T, error)) (T, error)

Call 通用 gRPC 调用:解析地址→取连接→注入 tenant/trace metadata→套超时→执行 fn。 fn 收到的 ctx 已注入 outgoing metadata 并带上 grpc.timeout 超时(毫秒,默认 5000)。 返回 fn 的原始结果/错误(不做跨进程业务码解包)。

func Dial

func Dial(ctx context.Context, svcName string) (*grpc.ClientConn, error)

Dial 按服务名解析地址(discovery.GetAddress)并返回(或复用池化)连接。 返回的连接为懒连接(grpc 默认行为),未就绪时在首次 RPC 才暴露错误。

Types

This section is empty.

Jump to

Keyboard shortcuts

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