std

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: AGPL-3.0 Imports: 1 Imported by: 6

Documentation

Index

Constants

View Source
const (
	SysComponentManger = "sys-component-manager"
	SysConfig          = "sys-config"
	SysLogger          = "sys-logger"
	SysTracer          = "sys-tracer"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface{}

Component 组件,在这里特指 `Injectable Component`

type ComponentId

type ComponentId string

type ComponentInstance

type ComponentInstance struct {
	Id        string
	Component Component
	IsInstall bool
	Lazing    bool
}

ComponentInstance 组件实例,是组件的容器

type ComponentManager

type ComponentManager interface {
	// Load 装载,将需要`依赖注入`的`Injectable Component` 装载到 组件管理器
	Load(Component, ...interface{}) ComponentManager

	// ReplaceLoad 替换装载,会替换掉 组件管理器中一个 组件
	ReplaceLoad(string, Component) ComponentManager

	// Install 安装,完成各组件的依赖注入绑定
	Install() ComponentManager

	// GetInstances 获取所有`组件实例`
	GetInstances() []*ComponentInstance

	// GetInstancesByType  按类型获取组件
	GetInstancesByType(t reflect.Type) []*ComponentInstance

	// GetInstanceById 通过ID获取一个组件
	GetInstanceById(string) *ComponentInstance
}

ComponentManager 组件管理器,完成依赖注入的核心容器

type Configure

type Configure interface {
	//Get 将获取`key`所对应的值,值将写入到参数`v`中;参数`v`,只接受指针类型;如果`key`对应的值不存在,将使用defaultVal
	Get(key string, v interface{}, defaultVal string) error
}

Configure 配置接口

type GinContent

type GinContent interface {
	Next()
	GetHeader(key string) string
}

type InstallAfter

type InstallAfter interface {
	AfterInstall()
}

InstallAfter Install后 调用

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Print(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Println(args ...interface{})
	Warnln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
}

Logger 日志接口

type ProcessError

type ProcessError error

type Processor

type Processor interface {

	//Process 处理函数;`std.ProcessError`用于标识`std.Processor`,一般情况函数应该返回`nil`,否则会产生panic
	Process() ProcessError
}

Processor 处理器;一种内置定义的特殊组件,该类型的`Injectable Component`在`Install`后,`Process() ProcessError`函数会被自动执行

type SingletonFactory

type SingletonFactory interface {
	Make() (id ComponentId, component Component)
}

SingletonFactory 单例工厂;一种内置定义的特殊组件,该类型的`Injectable Component`,函数(`Make() (id ComponentId, component Component)`) 在`Install`阶段会被调用,并且会将得到的`Injectable Component` 装载(`Load`)到组件管理器中

type Tracer

type Tracer interface {
	//Trace 中间件函数,用于将traceId加入到服务调用链中
	Trace(context GinContent)

	//SetTraceId 设置TraceId;给调用函数设置一个`traceId`,如果traceId为空字符串,将生成自动一个
	SetTraceId(traceId string, fn func())

	//GetTraceId 获取当前协程的traceId
	GetTraceId() string

	//Go 开启一个新的协程,用于替代语法操作`go fn()`,在新的协程中将自动携带当前协程的`traceId`
	Go(fn func())

	RecoverProcess()

	RecoverSetTraceId(traceId string, fn func())
}

Tracer 日志追踪,用于给同一个调用链路赋予统一的traceId,方便日志追踪

Jump to

Keyboard shortcuts

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