Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAndBury(cemetery Cemetery, goner Goner, goneId GonerId)
- func ExecuteInjectWrapFn(fn *reflect.Value) (results []any)
- func GetFuncName(f any) string
- func GetInterfaceType[T any](t *T) reflect.Type
- func InjectWrapFn(cemetery Cemetery, fn any) (*reflect.Value, error)
- func NewSimpleLogger() (Goner, GonerId)
- func PanicTrace(kb int) []byte
- func Run(priests ...Priest)
- func Serve(priests ...Priest)
- func Test[T Goner](fn func(T), priests ...Priest)
- func TestAt[T Goner](id GonerId, fn func(T), priests ...Priest)
- type AfterReviveError
- type Angel
- type BError
- type BuryMockCemetery
- type BusinessError
- type CMuxServer
- type Cemetery
- type Context
- type DefaultLogger
- type Error
- func CannotFoundGonerByIdError(id GonerId) Error
- func CannotFoundGonerByTypeError(t reflect.Type) Error
- func GonerIdIsExistedError(id GonerId) Error
- func NewError(code int, msg string) Error
- func NewInnerError(msg string, code int) Error
- func NewParameterError(msg string, ext ...int) Error
- func NotCompatibleError(a reflect.Type, b reflect.Type) Error
- func ReplaceBuryIdParamEmptyError() Error
- func ToError(input any) Error
- type Flag
- type GinMountError
- type Goner
- type GonerId
- type HandlerFunc
- type Heaven
- type IRouter
- type IRoutes
- type InnerError
- type Logger
- type Preparer
- type Priest
- type Process
- type Prophet
- type Prophet2
- type ResponseWriter
- type RouteGroup
- type SetLoggerError
- type SimpleLogger
- type SuckError
- type TestHeaven
- type Tomb
- type Tombs
- type Tracer
- type Vampire
- type Vampire2
- type XormEngine
Constants ¶
const ( // GonerIdIsExisted GonerId 不存在 GonerIdIsExisted = 1001 + iota // CannotFoundGonerById 通过GonerId查找Goner失败 CannotFoundGonerById // CannotFoundGonerByType 通过类型查找Goner失败 CannotFoundGonerByType //NotCompatible 类型不兼容 NotCompatible //ReplaceBuryIdParamEmpty 替换性下葬,GonerId不能为空 ReplaceBuryIdParamEmpty StartError StopError DbRollForPanic )
错误代码:gone框架内部错误代码编码空间:1001~1999
const ( // IdGoneHeaven 天堂组件的ID,代码了程序本身,Gone程序启动时默认注入 IdGoneHeaven = "gone-heaven" // IdGoneCemetery 坟墓组件的ID,是完成依赖注入的关键组件,Gone程序启动时默认注入 IdGoneCemetery = "gone-cemetery" //IdGoneTestKit 测试箱,调用 gone.Test 或者 gone.TestAt 时,会将测试箱注入到程序;非测试代码中不应该注入该组件 IdGoneTestKit = "gone-test-kit" //IdConfig 配置 Goner 的ID,提过能配置能力 IdConfig = "config" //IdGoneConfigure 配置器 Goner 的ID IdGoneConfigure = "gone-configure" // IdGoneTracer Tracer Goner 的ID,提供日志追踪能力 IdGoneTracer = "gone-tracer" // IdGoneLogger 日志 Goner 的ID,用于日志打印 IdGoneLogger = "gone-logger" //IdGoneCMux [cmux Goner](/goner/cmux#Server) ID IdGoneCMux = "gone-cmux" //IdGoneGin Gin相关的组件ID,可以使用 [goner.GinPriest](goner#GinPriest) 牧师函数批量安葬 IdGoneGin = "gone-gin" IdGoneGinRouter = "gone-gin-router" IdGoneGinProcessor = "gone-gin-processor" IdGoneGinProxy = "gone-gin-proxy" IdGoneGinResponser = "gone-gin-responser" IdHttpInjector = "http" //IdGoneXorm Xorm Goner 的ID,封装了xorm,用于操作数据库;使用 [goner.XormPriest](goner#XormPriest) 牧师函数安葬 IdGoneXorm = "gone-xorm" //IdGoneRedisPool redis pool goner; redis 相关 Goner,使用 [goner.RedisPriest](goner#RedisPriest) 牧师函数安葬 IdGoneRedisPool = "gone-redis-pool" IdGoneRedisCache = "gone-redis-cache" IdGoneRedisKey = "gone-redis-key" IdGoneRedisLocker = "gone-redis-locker" IdGoneRedisProvider = "gone-redis-provider" // IdGoneSchedule 定时器Goner;使用 [goner.SchedulePriest](goner#SchedulePriest) 牧师函数安葬 IdGoneSchedule = "gone-schedule" IdGoneReq = "gone-urllib" )
Gone框架中的内置组件ID
Variables ¶
var AfterStopSignalWaitSecond = 5
AfterStopSignalWaitSecond 收到停机信号后,退出程序等待的时间
Functions ¶
func CheckAndBury ¶
func ExecuteInjectWrapFn ¶ added in v0.2.1
func GetInterfaceType ¶ added in v0.0.17
GetInterfaceType 获取接口的类型
func InjectWrapFn ¶ added in v0.2.1
func NewSimpleLogger ¶ added in v0.0.8
func Run ¶
func Run(priests ...Priest)
Run 开始运行一个Gone程序;`gone.Run` 和 `gone.Serve` 的区别是: 1. gone.Serve启动的程序,主协程会调用 Heaven.WaitEnd 挂起等待停机信号,可以用于服务程序的开发 2. gone.Run启动的程序,主协程则不会挂起,运行完就结束,适合开发一致性运行的代码
// 定义加载服务的Priest函数
func LoadServer(c Cemetery) error {
c.Bury(goneXorm.New())
c.Bury(goneGin.New())
return nil
}
// 加载组件的Priest函数
func LoadComponent(c Cemetery) error {
c.Bury(componentA.New())
c.Bury(componentB.New())
}
gone.Run(LoadServer, LoadComponent)//开始运行
func Test ¶ added in v0.0.6
Test 用于编写测试用例,参考[示例](https://github.com/gone-io/gone/blob/main/example/test/goner_test.go)
Types ¶
type AfterReviveError ¶ added in v0.0.6
type AfterReviveError error
type BError ¶ added in v0.3.0
type BError struct {
// contains filtered or unexported fields
}
BError 业务错误
type BuryMockCemetery ¶
type BuryMockCemetery struct {
Cemetery
// contains filtered or unexported fields
}
func (*BuryMockCemetery) GetTomById ¶
func (c *BuryMockCemetery) GetTomById(id GonerId) Tomb
func (*BuryMockCemetery) GetTomByType ¶
func (c *BuryMockCemetery) GetTomByType(t reflect.Type) (list []Tomb)
type BusinessError ¶ added in v0.3.0
func NewBusinessError ¶ added in v0.3.0
func NewBusinessError(msg string, ext ...any) BusinessError
NewBusinessError 新建`业务错误`
type CMuxServer ¶ added in v1.0.0
Server cumx 服务,用于复用同一端口监听多种协议,参考文档:https://pkg.go.dev/github.com/soheilhy/cmux
type Cemetery ¶
type Cemetery interface {
Goner
//Bury a Goner to the Cemetery
Bury(Goner, ...GonerId) Cemetery
//ReplaceBury replace the Goner in the Cemetery with a new Goner
ReplaceBury(Goner, GonerId) error
//ReviveOne Revive a Goner from the Cemetery
ReviveOne(goner any) (deps []Tomb, err error)
//ReviveAllFromTombs Revive all Goner from the Cemetery
ReviveAllFromTombs() error
//GetTomById return the Tomb by the GonerId
GetTomById(GonerId) Tomb
//GetTomByType return the Tombs by the GonerType
GetTomByType(reflect.Type) []Tomb
// contains filtered or unexported methods
}
Cemetery which is for burying and reviving Goner
func NewBuryMockCemeteryForTest ¶ added in v1.0.0
func NewBuryMockCemeteryForTest() Cemetery
type DefaultLogger ¶ added in v0.2.1
type DefaultLogger interface {
SetLogger(logger SimpleLogger) SetLoggerError
}
type Error ¶
Error normal error
func GonerIdIsExistedError ¶
func NewInnerError ¶ added in v0.0.6
func NewParameterError ¶ added in v0.3.0
NewParameterError 新建`参数错误`
func ReplaceBuryIdParamEmptyError ¶
func ReplaceBuryIdParamEmptyError() Error
type GinMountError ¶ added in v0.3.0
type GinMountError error
type Goner ¶
type Goner interface {
// contains filtered or unexported methods
}
Goner which is an abstraction of injectable objects: can inject other Goner, can be injected by other Goner.
type HandlerFunc ¶ added in v0.3.0
type HandlerFunc any
type Heaven ¶
type Heaven interface {
//Install do some prepare before start
Install() Heaven
//WaitEnd make program block until heaven stop
WaitEnd() Heaven
//End send a signal to heaven to stop
End() Heaven
//Start make heaven start
Start() Heaven
Stop() Heaven
//GetHeavenStopSignal return a channel to listen the signal of heaven stop
GetHeavenStopSignal() <-chan struct{}
//BeforeStart add a hook function which will execute before start;
BeforeStart(Process) Heaven
//AfterStart add a hook function which will execute after start
AfterStart(Process) Heaven
//BeforeStop add a hook function which will execute before stop
BeforeStop(Process) Heaven
//AfterStop add a hook function which will execute after stop
AfterStop(Process) Heaven
}
type IRouter ¶ added in v0.3.0
type IRouter interface {
// IRoutes 1. 组合了`gone.IRoutes`,可以定义路由
IRoutes
// GetGinRouter 2. 可以获取被封装的ginRouter对象,用于操作原始的gin路由
GetGinRouter() gin.IRouter
// Group 3.定义路由分组
Group(string, ...HandlerFunc) RouteGroup
LoadHTMLGlob(pattern string)
}
type IRoutes ¶ added in v0.3.0
type IRoutes interface {
// Use 在路由上应用`gin`中间件
Use(...HandlerFunc) IRoutes
Handle(string, string, ...HandlerFunc) IRoutes
Any(string, ...HandlerFunc) IRoutes
GET(string, ...HandlerFunc) IRoutes
POST(string, ...HandlerFunc) IRoutes
DELETE(string, ...HandlerFunc) IRoutes
PATCH(string, ...HandlerFunc) IRoutes
PUT(string, ...HandlerFunc) IRoutes
OPTIONS(string, ...HandlerFunc) IRoutes
HEAD(string, ...HandlerFunc) IRoutes
}
type InnerError ¶ added in v0.0.6
InnerError which has stack
type Logger ¶
type Logger interface {
Tracef(format string, args ...any)
Debugf(format string, args ...any)
Infof(format string, args ...any)
Printf(format string, args ...any)
Warnf(format string, args ...any)
Warningf(format string, args ...any)
Errorf(format string, args ...any)
Fatalf(format string, args ...any)
Panicf(format string, args ...any)
Trace(args ...any)
Debug(args ...any)
Info(args ...any)
Print(args ...any)
Warn(args ...any)
Warning(args ...any)
Error(args ...any)
Fatal(args ...any)
Panic(args ...any)
Traceln(args ...any)
Debugln(args ...any)
Infoln(args ...any)
Println(args ...any)
Warnln(args ...any)
Warningln(args ...any)
Errorln(args ...any)
Fatalln(args ...any)
Panicln(args ...any)
}
Logger log interface
type Preparer ¶ added in v0.2.1
type Preparer struct {
// contains filtered or unexported fields
}
func (*Preparer) AfterStart ¶ added in v0.2.1
func (*Preparer) BeforeStart ¶ added in v0.2.1
func (*Preparer) BeforeStop ¶ added in v0.2.1
type Priest ¶
Priest A function which has A Cemetery parameter, and return an error. use for Burying Goner
type Process ¶
Process a function which has a Cemetery parameter, and return an error. use for hooks
func WrapNormalFnToProcess ¶ added in v0.2.1
type Prophet ¶ added in v0.0.6
type Prophet interface {
Goner
//AfterRevive A method which will execute after revive
// Deprecate: use `AfterRevive() error` instead
AfterRevive() AfterReviveError
}
Prophet A interface which has a AfterRevive method
type ResponseWriter ¶ added in v0.3.0
type ResponseWriter = gin.ResponseWriter
type RouteGroup ¶ added in v0.3.0
type RouteGroup interface {
IRouter
}
RouteGroup 路由分组 注入默认的路由分组使用Id: gone-gin-router (`gone.IdGoneGinRouter`)
type SetLoggerError ¶ added in v0.0.17
type SetLoggerError error
type SimpleLogger ¶ added in v0.3.0
type TestHeaven ¶
type TestHeaven[T Goner] interface { Heaven WithId(id GonerId) TestHeaven[T] WithPriest(priests ...Priest) TestHeaven[T] Run() }
func TestKit ¶
func TestKit[T Goner](fn func(T)) TestHeaven[T]
type Tomb ¶
type Tomb interface {
SetId(GonerId) Tomb
GetId() GonerId
GetGoner() Goner
GonerIsRevive(flags ...bool) bool
}
Tomb container of Goner
type Tracer ¶ added in v0.3.0
type Tracer interface {
//SetTraceId to set `traceId` to the calling function. If traceId is an empty string, an automatic one will
//be generated. TraceId can be obtained by using the GetTraceId () method in the calling function.
SetTraceId(traceId string, fn func())
//GetTraceId Get the traceId of the current goroutine
GetTraceId() string
//Go Start a new goroutine instead of `go func`, which can pass the traceid to the new goroutine.
Go(fn func())
//Recover use for catch panic in goroutine
Recover()
//RecoverSetTraceId SetTraceId and Recover
RecoverSetTraceId(traceId string, fn func())
}
Tracer Log tracking, which is used to assign a unified traceId to the same call link to facilitate log tracking.