Documentation
¶
Index ¶
Constants ¶
View Source
const ( //EnvProduction代表生产环境 EnvProduction = "production" //EnvTesting代表测试环境 EnvTesting = "testing" //EnvDevelopment代表开发环境 EnvDevelopment = "development" //EnvKey是环境变量服务字符串凭证 EnvKey = "hade:env" )
View Source
const ( TraceKeyTraceID = "trace_id" TraceKeySpanID = "span_id" TraceKeyCspanID = "cspan_id" TraceKeyParentID = "parent_id" TraceKeyMethod = "method" TraceKeyCaller = "caller" TraceKeyTime = "time" )
View Source
const AppKey = "hade:app"
AppKey定义字符串凭证
View Source
const (
ConfigKey = "hade:config"
)
View Source
const DistributedKey = "hade:distributed"
DistributedKey定义字符串凭证
View Source
const IDKey = "hade:id"
View Source
const KernelKey = "hade:kernel"
KernelKey提供kernel服务凭证
View Source
const LogKey = "hade:log"
协议关键字
View Source
const TraceKey = "hade:trace"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
//AppID表示当前这个app的唯一id,可以用于分布式锁等
AppID() string
//Version定义当前版本
Version() string
//BaseFolder定义项目基础地址
BaseFolder() string
//ConfigFolder定义了配置文件路径
ConfigFolder() string
//LogFolder定义了日志所在路径
LogFolder() string
//ProvideFolder定义业务自己的服务提供者地址
ProvideFolder() string
//MiddlewareFolder定义业务自己的中间件
MiddlewareFolder() string
//CommandFolder定义业务定义的命令
CommandFolder() string
//RuntimeFolder定义业务的运行中间态信息
RuntimeFolder() string
//TestFolder存放测试所需要的信息
TestFolder() string
//AppFolder定义业务代码所在的目录,用于监控文件变更使用
AppFolder() string
//LoadAppConfig加载新的AppConfig,key为对应的函数转为小写下划线,比如ConfigFolder => config_folder
LoadAppConfig(kv map[string]string)
}
App定义接口
type Config ¶
type Config interface {
//IsExist检查一个属性是否存在
IsExist(key string) bool
//Get获取一个属性值
Get(key string) interface{}
//GetBool获取一个bool属性
GetBool(key string) bool
//GetInt获取一个int属性
GetInt(key string) int
//GetFloat64获取一个float64属性
GetFloat64(key string) float64
//GetTime获取一个time属性
GetTime(key string) time.Time
//GetString获取一个string属性
GetString(key string) string
//GetIntSlice获取一个int切片属性
GetIntSlice(key string) []int
//GetStringSlice获取一个string切片
GetStringSlice(key string) []string
//GetStringMap获取一个string为key,interface为val的map
GetStringMap(key string) map[string]interface{}
//GetStringMapString获取一个string为key,string为val的map
GetStringMapString(key string) map[string]string
//GetStringMapStringSlice获取一个string为key,string切片为val的map
GetStringMapStringSlice(key string) map[string][]string
//Load加载配置到某个对象
Load(key string, val interface{}) error
}
Config定义了配置文件服务,读取配置文件,支持点分割的路径读取 例如:.Get("app.name")表示从app文件中读取name属性 建议使用yaml属性
type CtxFielder ¶
CtxFielder定义了从context中获取信息的方法
type Distributed ¶
type Distributed interface {
//Select分布式选择器,所有节点对某个服务进行抢占,只选择其中一个节点
//ServiceName服务名字
//appID当前的AppID
//holdTime分布式选择器hold住的时间
//返回值
//selectAppID分布式选择器最终选择的App
//err异常才返回,如果没有被选择,不返回err
Select(serviceName string, appID string, holdTime time.Duration) (selectAppID string, err error)
}
Distributed分布式服务
type Env ¶
type Env interface {
//AppEnv获取当前的环境,建议分为development/testing/production
AppEnv() string
//IsExist判断一个环境变量是否有被设置
IsExist(string) bool
//Get获取某个环境变量,如果没有设置,返回""
Get(string) string
//All获取所有的环境变量,.env和运行环境变量融合后结果
All() map[string]string
}
Env定义环境变量服务
type Formatter ¶
type Formatter func(level LogLevel, t time.Time, msg string, fields map[string]interface{}) ([]byte, error)
Formatter定义了将日志信息组织成字符串的通用方法
type Kernel ¶
type Kernel interface {
//HttpEngine http.Handler结构,作为net/http框架使用,实际上是gin.Engine
HttpEngine() http.Handler
}
Kernel接口提供框架最核心的架构
type Log ¶
type Log interface {
//Panic表示会导致整个程序出现崩溃的日志信息
Panic(ctx context.Context, msg string, fields map[string]interface{})
//Fatal表示会导致当前这个请求出现提前终止的错误信息
Fatal(ctx context.Context, msg string, fields map[string]interface{})
//Error表示出现错误,但是不一定影响后续请求逻辑的错误信息
Error(ctx context.Context, msg string, fields map[string]interface{})
//Warn表示出现错误,但是一定不影响后续请求逻辑的报警信息
Warn(ctx context.Context, msg string, fields map[string]interface{})
//Info表示正常的日志信息输出
Info(ctx context.Context, msg string, fields map[string]interface{})
//Debug表示在调试状态下打印出来的日志信息
Debug(ctx context.Context, msg string, fields map[string]interface{})
//Trace表示最详细的信息,一般信息量比较大,可能包含调用堆栈等信息
Trace(ctx context.Context, msg string, fields map[string]interface{})
//SetLevel设置日志级别
SetLevel(level LogLevel)
//SetCtxFielder从context中获取上下文字段field
SetCtxFielder(handler CtxFielder)
//SetFormatter设置输出格式
SetFormatter(formatter Formatter)
//SetOutput设置输出管道
SetOutput(out io.Writer)
}
Log define interface for log
type LogLevel ¶
type LogLevel uint32
const ( //UnknownLevel表示未知的日志级别 UnknownLevel LogLevel = iota //PanicLevel level,panic表示会导致整个程序出现崩溃的错误信息 PanicLevel //FatalLevel level,fatal表示会导致当前整个请求出现提前终止的错误信息 FatalLevel //ErrorLevel level,error表示出现错误,但是一定不影响后续请求逻辑的报警信息 ErrorLevel //WarnLevel level,warn表示出现错误,但是一定不影响后续请求逻辑的报警信息 WarnLevel //InfoLevel level,info表示正常的日志信息输出 InfoLevel //DebugLevel level,debug表示在调试状态下打印出来的日志信息 DebugLevel //TraceLevel level,trace表示最详细的信息,一般信息量比较大,可能包含调用堆栈等信息 TraceLevel )
type Trace ¶
type Trace interface {
//WithContext register new trace to context
WithTrace(c context.Context, trace *TraceContext) context.Context
//GetTrace From trace context
GetTrace(c context.Context) *TraceContext
//NewTrace generate a new trace
NewTrace() *TraceContext
//StartSpan generate cspan for child call
StartSpan(trace *TraceContext) *TraceContext
//traceContext to map for logger
ToMap(trace *TraceContext) map[string]string
//GetTrace By Http
ExtractHTTP(req *http.Request) *TraceContext
//Set Trace to Http
InjectHTTP(req *http.Request, trace *TraceContext) *http.Request
}
Click to show internal directories.
Click to hide internal directories.