Documentation
¶
Index ¶
Constants ¶
View Source
const ( // 生产环境 EnvProduction = "production" // 测试环境 EnvTesting = "testing" // 开发环境 EnvDevelopment = "development" // 环境变量服务的字符串凭证 EnvKey = "anna:key" )
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 = "anan:app"
定义app字符串凭证
View Source
const CacheKey = "anan:cache"
View Source
const (
ConfigKey = "anan:config"
)
View Source
const DistributedKey = "anan:distributed"
字符串凭证
View Source
const KernelKey = "anan:kernel"
View Source
const LogKey = "anan:log"
View Source
const ORMKey = "anan:orm"
View Source
const RedisKey = "anan:redis"
View Source
const TraceKey = "anan:trace"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
// 表示当前这个app唯一的id
AppID() string
// 当前版本
Version() string
// 项目的根目录
BaseFolder() string
// 配置目录
ConfigFolder() string
// 日志目录
LogFolder() string
// 服务提供者目录
ProviderFolder() string
// 业务中间件目录
MiddlewareFolder() string
CommandFolder() string
RuntimeFolder() string
TestFolder() string
// 定义业务代码所在的目录
AppFolder() string
// LoadAppConfig 加载新的AppConfig,key为对应的函数转为小写下划线,比如ConfigFolder => config_folder
LoadAppConfig(kv map[string]string)
}
type CacheService ¶
type CacheService interface {
// get方法
Get(ctx context.Context, key string) (string, error)
GetObj(ctx context.Context, key string, model interface{}) error
GetMany(ctx context.Context, keys []string) (map[string]string, error)
// set 方法
Set(ctx context.Context, key string, val string, timeout time.Duration) error
SetObj(ctx context.Context, key string, val interface{}, timeout time.Duration) error
SetMany(ctx context.Context, data map[string]string, timeout time.Duration) error
SetForever(ctx context.Context, key string, val string) error
SetForeverObj(ctx context.Context, key string, val interface{}) error
// 设置某个key的超时时间
SetTTL(ctx context.Context, key string, timeout time.Duration) error
GetTTL(ctx context.Context, key string) (time.Duration, error)
Remember(ctx context.Context, key string, timeout time.Duration, rememberFunc RememberFunc, model interface{}) error
// 往key对应的值增加step
Calc(ctx context.Context, key string, step int64) (int64, error)
Increment(ctx context.Context, key string) (int64, error)
Decrement(ctx context.Context, key string) (int64, error)
Del(ctx context.Context, key string) error
DelMany(ctx context.Context, keys []string) error
}
缓存服务
type Config ¶
type Config interface {
IsExist(key string) bool
// 获取一个属性
Get(key string) interface{}
GetBool(key string) bool
GetInt(key string) int
GetFloat64(key string) float64
GetTime(key string) time.Time
GetString(key string) string
GetIntSlice(key string) []int
GetStringSlice(key string) []string
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringMapStringSlice(key string) map[string][]string
// 加载配置到某个项目
Load(key string, val interface{}) error
}
type DBConfig ¶
type DBConfig struct {
WriteTimeout string `yaml:"write_timeout"` // 写超时时间
Loc string `yaml:"log"` //时区
Port int `yaml:"port"` //端口
ReadTimeout string `yaml:"read_timeout"` //读超时时间
Charset string `yaml:"charset"` //字符集
ParseTime bool `yaml:"parse_time"` //是否转换时间类型
Protocol string `yaml:"protocol"` //传输协议
Dsn string `yaml:"dsn"` //
Database string `yaml:"database"`
Collation string `yaml:"collation"` // 字符序
Timeout string `yaml:"timeout"` //连接超时时间
Username string `yaml:"username"`
Password string `yaml:"password"`
Driver string `yaml:"driver"`
Host string `yaml:"host"`
// 以下配置关于连接池
ConnMaxIdle int `yaml:"conn_max_idle"` // 最大空闲连接数
ConnMaxOpen int `yaml:"conn_max_open"` // 最大连接数
ConnMaxLifetime string `yaml:"conn_max_lifetime"` // 连接最大生命周期
ConnMaxIdletime string `yaml:"conn_max_idle_time"` // 空闲最大生命周期
//配置gorm
*gorm.Config
}
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)
}
分布式服务
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(level LogLevel)
SetCtxFielder(handler CtxFielder)
SetFormatter(formatter Formatter)
SetOutput(out io.Writer)
}
type LogLevel ¶
type LogLevel uint32
const ( UnknowLevel 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 RedisConfig ¶
func (*RedisConfig) Uniqkey ¶
func (rc *RedisConfig) Uniqkey() string
type RedisOption ¶
type RedisOption func(container framework.Container, config *RedisConfig) error
修改option选项的方法
type RedisService ¶
type RedisService interface {
GetClient(option ...RedisOption) (*redis.Client, error)
}
一个redis服务
type RememberFunc ¶
Cache-aside模式对应的对象生成方法
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.