Documentation
¶
Index ¶
Constants ¶
View Source
const ( // EnvProduction 代表生产环境 EnvProduction = "production" // EnvTesting 代表测试环境 EnvTesting = "testing" // EnvDevelopment 代表开发环境 EnvDevelopment = "development" // EnvKey 环境变量服务字符串凭证 EnvKey = "gone: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 = "gone:app"
View Source
const ConfigKey = "gone:config"
View Source
const DistributedKey = "gone:distributed"
View Source
const IDKey = "gone:id"
View Source
const KernelKey = "gone:kernel"
View Source
const LogKey = "gone:log"
View Source
const TraceKey = "gone:trace"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
// Version 定义当前版本
Version() string
AppID() string
//BaseFolder 定义项目基础地址
BaseFolder() string
// ConfigFolder 定义了配置文件的路径
ConfigFolder() string
// StorageFolder 定义运行时文件存储路径
StorageFolder() string
// LogFolder 定义了日志所在路径
LogFolder() string
// ProviderFolder 定义业务自己的服务提供者地址
ProviderFolder() string
// HttpFolder http业务路径
HttpFolder() string
// MiddlewareFolder 定义业务自己定义的中间件
MiddlewareFolder() string
// ConsoleFolder 定义命令目录
ConsoleFolder() string
// CommandFolder 定义业务定义的命令
CommandFolder() string
// RuntimeFolder 定义业务的运行中间态信息
RuntimeFolder() string
// TestFolder 存放测试所需要的信息
TestFolder() string
// AppFolder 存放业务逻辑信息
AppFolder() string
// LoadAppConfig 加载新的AppConfig,key为对应的函数转为小写下划线,比如ConfigFolder => config_folder
LoadAppConfig(kv map[string]string)
}
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 获取一个字符串属性
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
}
type CtxFielder ¶
CtxFielder 定义了从上下文中获取信息的方法
type Distributed ¶
type Formatter ¶
type Formatter func(level LogLevel, t time.Time, msg string, fields map[string]interface{}) ([]byte, error)
Formatter 定义了将日志信息组织成字符串的通用方法
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 从上下文中获取上下文字段field
SetCtxFielder(handler CtxFielder)
// SetFormatter 设置输出格式
SetFormatter(formatter Formatter)
// SetOutput 设置输出管道
SetOutput(out io.Writer)
}
type LogLevel ¶
type LogLevel uint32
const ( // UnkonwLevel 表示未知的日志级别 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.