contract

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvProduction 生产环境
	EnvProduction = "production"
	// EnvTesting 测试环境
	EnvTesting = "testing"
	// EnvDevelopment 开发环境
	EnvDevelopment = "development"
	EnvKey         = "web: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 = "web:app"
View Source
const ConfigKey = "web:config"
View Source
const DistributedKey = "web:distributed"
View Source
const KernelKey = "web:kernel"
View Source
const LogKey = "web:log"
View Source
const TraceKey = "web:trace"

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App interface {
	// Version 当前版本
	Version() string
	// BaseFolder 项目基础目录
	BaseFolder() string
	// ConfigFolder config foler
	ConfigFolder() string
	// LogFolder the folder of log
	LogFolder() string
	// ProviderFolder the forlder of provider
	ProviderFolder() string
	// MiddlewareFolder middleware folder
	MiddlewareFolder() string
	// CommandFolder command folder
	CommandFolder() string
	// RuntimeFolder
	RuntimeFolder() string
	TestFolder() string
	// AppFolder 定义业务代码所在目录
	AppFolder() string
	// AppID
	AppID() string
	// LoadAppConfig
	LoadAppConfig(map[string]string)
}

type Config

type Config interface {
	// IsExists 检查一个属性是否存在
	IsExists(key string) bool
	Get(key string) any
	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]any
	GetStringMapString(key string) map[string]string
	GetStringMapStringSlice(key string) map[string][]string
	// Load 加载配置到某个对象
	Load(key string, val any) error
}

type CtxFielder

type CtxFielder func(ctx context.Context) map[string]any

CtxFielder 从context获取信息的方法

type Distributed

type Distributed interface {
	// Select
	// serviceName 服务名称
	// appID 当前AppID
	// holdTime 分布式选择器hold住的时间
	// selectAppId 分布式选择器最终选择的App
	Select(serviceName string, appID string, holdTime time.Duration) (selectAppID string, err error)
}

Distributed 分布式服务

type Env

type Env interface {
	// AppEnv 获取当前环境
	AppEnv() string
	// IsExists 判断环境变量是否被设置
	IsExists(string) bool
	// Get 获取环境变量
	Get(string) string
	// All 获取所有环境变量
	All() map[string]string
}

type Formatter

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

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

type Kernel

type Kernel interface {
	HttpEngine() http.Handler
}

type Log

type Log interface {
	// Panic 表示会导致整个程序出现崩溃的日志信息
	Panic(ctx context.Context, msg string, fields map[string]any)
	// Fatal 表示会导致当前这个请求出现提前终止的错误信息
	Fatal(ctx context.Context, msg string, fields map[string]any)
	// Error 表示出现错误信息,但是不一定影响后续请求逻辑的错误信息
	Error(ctx context.Context, msg string, fields map[string]any)
	// Warn 表示出现错误信息,但是不一定影响后续请求逻辑的报警信息
	Warn(ctx context.Context, msg string, fields map[string]any)
	// Info 正常的日志信息
	Info(ctx context.Context, msg string, fields map[string]any)
	// Debug 调试状态下打印出来的信息
	Debug(ctx context.Context, msg string, fields map[string]any)
	// Trace
	Trace(ctx context.Context, msg string, fields map[string]any)
	// SetLevel
	SetLevel(level LogLevel)

	// SetCtxFielder 从context中获取上下文字段field
	SetCtxFielder(hander CtxFielder)
	// SetFormatter 设置输出格式
	SetFormatter(formatter Formatter)
	// SetOutput 设置输出格式
	SetOutput(out io.Writer)
}

type LogLevel

type LogLevel uint32
const (
	UnknowLevel LogLevel = iota
	PanicLevel
	FatalLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

type Trace

type Trace interface {
	// WithTrace register new trace to context
	WithTrace(context.Context, *TraceContext) context.Context
	// GetTrace From trace context
	GetTrace(context.Context) *TraceContext
	// NewTrace generate a new trace
	NewTrace() *TraceContext
	// StartSpan generate cspan for child call
	StartSpan(*TraceContext) *TraceContext
	// ToMap 将logger转换为map
	ToMap(*TraceContext) map[string]string
	// 通过http
	ExtractHTTP(*http.Request) *TraceContext
	// 给http添加trace
	InjectHTTP(*http.Request, *TraceContext) *http.Request
}

type TraceContext

type TraceContext struct {
	TraceID    string // traceID global unique
	ParentID   string // 父节点SpanID
	SpanID     string // 当前节点SpanID
	CspanId    string // 子节点调用的SpanID,由调用方指定
	Annotation map[string]string
}

Jump to

Keyboard shortcuts

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