contract

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 4 Imported by: 0

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

type CtxFielder func(ctx context.Context) map[string]interface{}

CtxFielder 定义了从上下文中获取信息的方法

type Distributed

type Distributed interface {
	// 分布式选择器,所有节点对某个服务进行抢占,只选择其中一个节点
	// ServiceName 服务名字
	// appID 当AppID
	// holdTIme 分布式选择器hold住的时间
	// 返回值
	// selectAppID 分布式选择器最终选择的App
	Select(serviceName string, appID string, holdTime time.Duration) (selectAppID string, err error)
}

type Env

type Env interface {
	// AppEnv 获取当前环境,建议分为devlopment、testing、production
	AppEnv() string

	// IsExist 判断一个环境变量是否被设置
	IsExist(string) bool
	// Get 获取一个环境变量,没有设置,返回 ""
	Get(string) string
	// All 获取所有的环境变量,.env和运行环境变量合并后的结果
	All() map[string]string
}

type Formatter

type Formatter func(level LogLevel, t time.Time, msg string, fields map[string]interface{}) ([]byte, error)

Formatter 定义了将日志信息组织成字符串的通用方法

type IDService

type IDService interface {
	NewID() string
}

type Kernel

type Kernel interface {
	// 返回http.Handler, 可以方便我切换http服务核心
	// 比如可以使用gin.Engine,或者其他的只是实现了ServeHTTP方法的任意核心
	HttpEngine() http.Handler
}

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
}

type TraceContext

type TraceContext struct {
	// traceID global unique
	TraceID string
	// parentID 父节点SpanID
	ParentID string
	// 当前节点spanID
	SpanID string
	// 子节点调用的spanID,由调用方指定
	CspanID string

	// 标记各种信息
	Annotation map[string]string
}

Jump to

Keyboard shortcuts

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