Documentation ¶
Overview ¶
Package response 请求返回处理包
Index ¶
- Constants
- Variables
- type Exception
- type RespError
- type Response
- type Result
- func (result *Result) Callback(callback func() *Result, err error)
- func (result *Result) Fail(msg string)
- func (result *Result) FailErr(err error)
- func (result *Result) Say(context *gin.Context)
- func (result *Result) SayFail(context *gin.Context, msg string)
- func (result *Result) SaySuccess(context *gin.Context, obj interface{})
- func (result *Result) Success(obj interface{})
- func (result *Result) Write(context *gin.Context, byte []byte) (int, error)
- type Router
- func (router *Router) Any(relativePath string, f func(router *Router))
- func (router *Router) DELETE(relativePath string, f func(router *Router))
- func (router *Router) GET(relativePath string, f func(router *Router))
- func (router *Router) HEAD(relativePath string, f func(router *Router))
- func (router *Router) Handle(relativePath string, f func(router *Router))
- func (router *Router) OPTIONS(relativePath string, f func(router *Router))
- func (router *Router) PATCH(relativePath string, f func(router *Router))
- func (router *Router) POST(relativePath string, f func(router *Router))
- func (router *Router) PUT(relativePath string, f func(router *Router))
- func (router *Router) Static(relativePath, root string)
- func (router *Router) StaticFS(relativePath string, fs http.FileSystem)
- func (router *Router) StaticFile(relativePath, filepath string)
- func (router *Router) Use(relativePath string, f func(router *Router))
Constants ¶
const ( // Success 请求返回成功码 Success = "200" // Fail 请求返回失败码 Fail = "9999" )
Variables ¶
var ( // ExpNotExist 所请求事务不存在异常 ExpNotExist = Exp("not exist", http.StatusOK) )
Functions ¶
This section is empty.
Types ¶
type Exception ¶
type Exception struct { Msg string // 异常通用信息 // contains filtered or unexported fields }
Exception 自定义异常实体
type RespError ¶
type RespError struct { ErrorCode string ErrorMsg string // HTTPStatusCode http的错误编码 HTTPStatusCode int }
RespError 自定义 error 对象
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response 提供实例化调用 Do 方法,并内置返回策略
func SyncPoolGetResponse ¶
func SyncPoolGetResponse() *Response
SyncPoolGetResponse 提供实例化调用 Do 方法,并内置返回策略
func (*Response) Do ¶
Do 处理 request 请求
context:请求上下文
obj:请求中 body 中内容期望转换的对象并做空实例化,如 new(Type)
objBlock:obj 对象的回调方法,最终调用 Do 函数的方法会接收到返回值
objBlock interface{}:obj 对象的回调方法所返回的最终交由 response 输出的对象
objBlock error:obj 对象的回调方法所返回的错误对象
如未出现err,且无可描述返回内容,则返回值可为 (nil, nil)
func (*Response) DoSelf ¶
func (response *Response) DoSelf(context *gin.Context, self func(writer http.ResponseWriter, request *http.Request))
DoSelf 处理 request 请求
context:请求上下文
obj:请求中 body 中内容期望转换的对象并做空实例化,如 new(Type)
objBlock:obj 对象的回调方法,最终调用 Do 函数的方法会接收到返回值
objBlock interface{}:obj 对象的回调方法所返回的最终交由 response 输出的对象
objBlock error:obj 对象的回调方法所返回的错误对象
如未出现err,且无可描述返回内容,则返回值可为 (nil, nil)
type Result ¶
type Result struct { ResultCode string `json:"code"` Msg string `json:"msg"` // 数据接口 Data interface{} `json:"data"` }
Result 请求返回对象实体
func (*Result) SaySuccess ¶
SaySuccess response 返回请求成功对象
type Router ¶
Router 路由入口对象
func (*Router) Handle ¶
Handle registers a new request handle and middleware with the given path and method. The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes. See the example code in GitHub.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*Router) Static ¶
Static 路由 Static 请求方法 Static serves files from the given file system root. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler. To use the operating system's file system implementation, use :
router.Static("/static", "/var/www")
func (*Router) StaticFS ¶
func (router *Router) StaticFS(relativePath string, fs http.FileSystem)
StaticFS 路由 StaticFS 请求方法 StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead. Gin by default user: gin.Dir()
func (*Router) StaticFile ¶
StaticFile 路由 StaticFile 请求方法 StaticFile registers a single route in order to serve a single file of the local filesystem. router.StaticFile("favicon.ico", "./resources/favicon.ico")