void

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

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 ContextGetAppID(ctx context.Context) string

func ContextGetUserId

func ContextGetUserId(ctx context.Context) string

func ContextIsAdmin

func ContextIsAdmin(ctx context.Context) bool

func GetIncomingContext

func GetIncomingContext(ctx context.Context, name string) []string

func GetIncomingContextOne

func GetIncomingContextOne(ctx context.Context, name string) string

func GetOutgoingContext

func GetOutgoingContext(ctx context.Context, name string) []string

func GetOutgoingContextOne

func GetOutgoingContextOne(ctx context.Context, name string) string

func Init

func Init(config *Config) error

Init 初始化准备

func InitConfig

func InitConfig(flagMap map[string]cli.Flag)

InitConfig 初始化配置

func LogInterceptor

func LogInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

LogInterceptor 打印日志拦截器

func SetOutgoingContext

func SetOutgoingContext(ctx context.Context, kv []string) context.Context

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 AuthAPI struct {
	// API名称
	Name string
	// 是否需要认证
	NeedToken bool
	// 是否是管理员接口,管理员接口默认需要授权
	IsAdmin bool
	// contains filtered or unexported fields
}

func NewAuthAPI

func NewAuthAPI(name string, needToken bool, isAdmin bool, method interface{}) 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

type RPCMicroService struct {
	Name       string       // 服务名
	GRPCServer *grpc.Server // gRPC实例
}

RPCMicroService RPC类型的微服务

func NewRPCMicroService

func NewRPCMicroService(name string) (*RPCMicroService, error)

NewRPCMicroService 创建一个微服务

func (*RPCMicroService) Run

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微服务

Jump to

Keyboard shortcuts

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