gin

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequestIdHeaderKey = "X-Request-ID"
View Source
var TraceIdHeaderKey = "X-Trace-ID"

Functions

func NewGinProcessor

func NewGinProcessor() (gone.Prophet, gone.GonerId)

NewGinProcessor 创建系统级的`Processor`,该处理器将在路由上挂载多个中间件 `trace`,负责提供健康检查响应(需要在配置文件中设置健康检查的路径`server.health-check`) 和 为请求绑定唯一的`traceID` `recovery`,负责恢复请求内发生panic `statRequestTime`,用于在日志中打印统计的请求耗时,可以通过设置配置项(`server.log.show-request-time=false`)来关闭 `accessLog`,用于在日志中打印请求、响应信息

func NewGinProxy

func NewGinProxy() (gone.Goner, gone.GonerId)

NewGinProxy 新建代理器

func NewGinResponser

func NewGinResponser() (gone.Goner, gone.GonerId)

NewGinResponser 新建系统默认的响应处理器 注入的ID为:gone-gin-responser (`gone.IdGoneGinResponser`)

func NewGinRouter

func NewGinRouter() (gone.Goner, gone.GonerId)

NewGinRouter 用于创建系统根路由

func NewGinServer

func NewGinServer() (gone.Angel, gone.GonerId)

func NewInnerError

func NewInnerError(msg string, code int) gone.Error

func NewParameterError

func NewParameterError(msg string, ext ...int) gone.Error

NewParameterError 新建`参数错误`

func Priest

func Priest(cemetery gone.Cemetery) error

func ToError

func ToError(err error) gone.Error

ToError 将 golang 提供的 error 转为一个 `gone.Error`

Types

type BusinessError

type BusinessError interface {
	gone.Error
	Data() interface{}
}

BusinessError 2. BusinessError,业务错误 业务错误是业务上的特殊情况,需要在不同的业务场景返回不同的数据类型;本质上不算错误,是为了便于业务编写做的一种抽象, 让同一个接口拥有在特殊情况返回不同业务代码和业务数据的能力

func NewBusinessError

func NewBusinessError(msg string, ext ...interface{}) BusinessError

NewBusinessError 新建`业务错误`

type Close

type Close func()

type Context

type Context struct {
	*gin.Context
}

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) Write

func (w CustomResponseWriter) Write(b []byte) (int, error)

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 HandlerFunc

type HandlerFunc func(*Context) (interface{}, error)

HandlerFunc `gone`框架的路由处理函数

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`)

type RouterGroupName

type RouterGroupName string

RouterGroupName 路由分组名称

type Server

type Server interface {
	gone.Angel

	// Serve 启动http服务,返回的函数可以用于"服务优雅停机"
	Serve() (close Close)
}

Server `gone`服务,可以代表一个`gone`应用 注入`gin.Server`使用Id:gone-gin (`gone.IdGoneGin`)

Jump to

Keyboard shortcuts

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