Documentation ¶
Index ¶
- Variables
- func NewGinProcessor() (gone.Prophet, gone.GonerId)
- func NewGinProxy() (gone.Goner, gone.GonerId)
- func NewGinResponser() (gone.Goner, gone.GonerId)
- func NewGinRouter() (gone.Goner, gone.GonerId)
- func NewGinServer() (gone.Angel, gone.GonerId)
- func NewInnerError(msg string, code int) gone.Error
- func NewParameterError(msg string, ext ...int) gone.Error
- func Priest(cemetery gone.Cemetery) error
- func ToError(err error) gone.Error
- type BusinessError
- type Close
- type Context
- type Controller
- type CustomResponseWriter
- type HandleProxyToGin
- type HandlerFunc
- type IRouter
- type IRoutes
- type MountError
- type Responser
- type RouteGroup
- type RouterGroupName
- type Server
Constants ¶
This section is empty.
Variables ¶
var RequestIdHeaderKey = "X-Request-ID"
var TraceIdHeaderKey = "X-Trace-ID"
Functions ¶
func NewGinProcessor ¶
NewGinProcessor 创建系统级的`Processor`,该处理器将在路由上挂载多个中间件 `trace`,负责提供健康检查响应(需要在配置文件中设置健康检查的路径`server.health-check`) 和 为请求绑定唯一的`traceID` `recovery`,负责恢复请求内发生panic `statRequestTime`,用于在日志中打印统计的请求耗时,可以通过设置配置项(`server.log.show-request-time=false`)来关闭 `accessLog`,用于在日志中打印请求、响应信息
func NewGinResponser ¶
NewGinResponser 新建系统默认的响应处理器 注入的ID为:gone-gin-responser (`gone.IdGoneGinResponser`)
func NewParameterError ¶
NewParameterError 新建`参数错误`
Types ¶
type BusinessError ¶
BusinessError 2. BusinessError,业务错误 业务错误是业务上的特殊情况,需要在不同的业务场景返回不同的数据类型;本质上不算错误,是为了便于业务编写做的一种抽象, 让同一个接口拥有在特殊情况返回不同业务代码和业务数据的能力
func NewBusinessError ¶
func NewBusinessError(msg string, ext ...interface{}) BusinessError
NewBusinessError 新建`业务错误`
type Controller ¶
type Controller interface { // Mount 路由挂载接口,改接口会在服务启动前被调用,该函数的实现通常情况应该返回`nil` Mount() MountError }
Controller 控制器接口,由业务代码编码实现,用于挂载和处理路由 使用方式参考 [示例代码](https://gitlab.openviewtech.com/gone/gone-example/-/tree/master/gone-app)
type CustomResponseWriter ¶
type CustomResponseWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
func (CustomResponseWriter) WriteString ¶
func (w CustomResponseWriter) WriteString(s string) (int, error)
type HandleProxyToGin ¶
type HandleProxyToGin interface {
Proxy(handler ...HandlerFunc) []gin.HandlerFunc
}
HandleProxyToGin 代理器,提供一个proxy函数将`gin.HandlerFunc`转成`gin.HandlerFunc` 注入`gin.HandleProxyToGin`使用Id:sys-gone-proxy (`gin.SystemGoneProxy`)
type IRouter ¶
type IRouter interface { // IRoutes 1. 组合了`gone.IRoutes`,可以定义路由 IRoutes // GetGinRouter 2. 可以获取被封装的ginRouter对象,用于操作原始的gin路由 GetGinRouter() gin.IRouter // Group 3.定义路由分组 Group(string, ...gin.HandlerFunc) RouteGroup }
IRouter `gone`框架基于`gin`封装的"路由器" 注入默认的路由器使用Id: gone-gin-router (`gone.IdGoneGinRouter`)
type IRoutes ¶
type IRoutes interface { // Use 在路由上应用`gin`中间件 Use(...gin.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 }
IRoutes `gone`框架基于`gin`封装的路由,用于定义处理特定请求的函数 注入默认的路由使用Id: gone-gin-router (`gone.IdGoneGinRouter`) 给对象`inject`路由依赖: ```go
func NewDependOnIRoutes() *DependOnIRoutes { return &DependOnIRoutes{} } type DependOnIRoutes struct { TheRoutes gone.IRoutes `gone:"gone-gin-router"` //依赖注入系统路由 } func (*DependOnIRoutes)DoSomething() { //对路由进行操作 //... }
```
type MountError ¶
type MountError error
MountError `gin.Controller#Mount`返回的类型,用于识别 `gin.Controller` 的实现,避免被错误的调用到
type Responser ¶
type Responser interface { gone.Goner Success(ctx jsonWriter, data interface{}) Failed(ctx jsonWriter, err error) }
Responser 响应处理器 注入默认的响应处理器使用Id: gone-gin-responser (`gone.IdGoneGinResponser`)
type RouteGroup ¶
type RouteGroup interface { IRouter }
RouteGroup 路由分组 注入默认的路由分组使用Id: gone-gin-router (`gone.IdGoneGinRouter`)