Documentation ¶
Index ¶
- Variables
- func AuthGRPCInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func ContextFieldInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func ContextGetAppID(ctx context.Context) string
- func ContextGetUserId(ctx context.Context) string
- func ContextIsAdmin(ctx context.Context) bool
- func GetIncomingContext(ctx context.Context, name string) []string
- func GetIncomingContextOne(ctx context.Context, name string) string
- func GetOutgoingContext(ctx context.Context, name string) []string
- func GetOutgoingContextOne(ctx context.Context, name string) string
- func Init(config *Config) error
- func InitConfig(flagMap map[string]cli.Flag)
- func LogInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func SetOutgoingContext(ctx context.Context, kv []string) context.Context
- func TraceInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- type AuthAPI
- type Config
- type ContextFieldRule
- type RPCMicroService
- type RPCMicroServiceRunHooks
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // AuthAppIdMap 允许的AppId列表,外部需要定时从管理服务加载 AuthAppIdMap = sync.Map{} // AuthAPIMap 接口列表 AuthAPIMap = map[string]AuthAPI{} // AuthServiceInterface 授权服务 AuthServiceInterface mysession.Interface )
View Source
var ( // Debug 调试模式 Debug = false // ListeningAddress TCP监听地址 ListeningAddress = ":10000" // ListeningHTTPGateWayAddress HTTP监听地址 ListeningHTTPGateWayAddress = ":10001" ListeningHTTPGateWay = false // ListeningHTTPProfAddress HTTP监听地址 ListeningHTTPProfAddress = ":10002" ListeningHTTPProf = false // LogLevel LogMaxAge 日志配置 LogLevel = "debug" // 日志级别 LogJson = false // 日志输出格式 LogPath = "./log" // 日志路径 LogName = "log.log" // 日志文件名 // Environment 哪个环境 Environment = "Development" )
全局配置
View Source
var ( // ContextAuthorizationValuePrefix 授权令牌值前缀 ContextAuthorizationValuePrefix = "bearer" // ContextTraceId 日志追踪ID ContextTraceId = "trace.id" // ContextAppId 应用ID ContextAppId = "app.id" // ContextUserId 应用用户ID ContextUserId = "app.session.user.id" // ContextAppAdmin 管理员标记 ContextAppAdmin = "app.session.user.admin" // ContextAppAdminYes 是否管理员 ContextAppAdminYes = "admin" )
View Source
var ( // LogMaxAge 日志保存时间 LogMaxAge = 30 * 24 * time.Hour // LogRotationTime 日志切割周期 LogRotationTime = 24 * time.Hour )
View Source
var ( // ContextFieldList 需要额外处理的上下文 ContextFieldList = []ContextFieldRule{ { Name: ContextAppId, Require: true, One: true, Through: true, }, { Name: ContextAppAdmin, Require: false, One: true, Through: true, }, { Name: ContextUserId, Require: false, One: true, Through: true, }, } )
View Source
var ( // NewrelicApplication 追踪实例,单例模式 NewrelicApplication *newrelic.Application )
View Source
var NewrelicLicense = "xxx"
NewrelicLicense 打点凭证
View Source
var SkipLogInterceptor = true
View Source
var ( // UseNewrelic 是否使用该打点 UseNewrelic bool )
Functions ¶
func AuthGRPCInterceptor ¶
func AuthGRPCInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
func ContextFieldInterceptor ¶
func ContextFieldInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
ContextFieldInterceptor 上下文透传处理拦截器
func ContextGetAppID ¶
func ContextGetUserId ¶
func ContextIsAdmin ¶
func LogInterceptor ¶
func LogInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
LogInterceptor 打印日志拦截器
func TraceInterceptor ¶
func TraceInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
TraceInterceptor 追踪ID拦截器
Types ¶
type AuthAPI ¶
type Config ¶
type Config struct { // 应用名 AppName string // 应用使用介绍 AppUsage string // 加载自定义配置 LoadDiyFlagConfig func(map[string]cli.Flag) // 加载其他初始化 LoadInitPrepare func() error // 是否使用打点 UseNewrelic bool }
Config 初始化配置
type ContextFieldRule ¶
type ContextFieldRule struct { // 字段名 Name string // 是否必有值 Require bool // 单值 One bool // 透传 Through bool }
ContextFieldRule 上下文字段传输规则
type RPCMicroService ¶
RPCMicroService RPC类型的微服务
func NewRPCMicroService ¶
func NewRPCMicroService(name string) (*RPCMicroService, error)
NewRPCMicroService 创建一个微服务
func (*RPCMicroService) Run ¶
func (s *RPCMicroService) Run(vars *RPCMicroServiceRunHooks) error
Run 运行微服务
type RPCMicroServiceRunHooks ¶
type RPCMicroServiceRunHooks struct { // 非空时且是调试模式时使用 TCPAddress string // 注册gRPC服务 RegisterRPCServer func(gRPCServer *grpc.Server) // gRPC服务一元拦截器 RegisterRPCServerUnaryInterceptor []grpc.UnaryServerInterceptor // gRPC服务流拦截器 RegisterRPCServerStreamInterceptor []grpc.StreamServerInterceptor // 注册HTTP代理服务 RegisterHTTPGateWayServer func(httpServer *runtime.ServeMux, endpoint string, opts []grpc.DialOption) // 切面到最后执行的函数 AopEndFunc func() error }
RPCMicroServiceRunHooks 微服务勾子,用来注册gRPC微服务
Click to show internal directories.
Click to hide internal directories.