context

package
v0.0.0-...-fc50bb1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextHandler

func ContextHandler(handler ContextHandlerFunc) gin.HandlerFunc

上下文处理

Types

type Context

type Context struct {
	*gin.Context

	// 认证 Key
	Authorization string

	// 响应数据包内容
	ResponseBuilder ResponseBuilder
}

上下文结构体

func (*Context) Error

func (ctx *Context) Error(code int)

API 失败响应

func (*Context) GetContextAuthorization

func (ctx *Context) GetContextAuthorization() string

获取 认证 Key

func (*Context) RequestValidate

func (ctx *Context) RequestValidate(validate interface{}) (ok bool)

请求数据验证

func (*Context) SetContextAuthorization

func (ctx *Context) SetContextAuthorization(value string)

设置 认证 Key

func (*Context) Success

func (ctx *Context) Success(data H)

API 成功响应

type ContextHandlerFunc

type ContextHandlerFunc func(ctx *Context)

上下文处理函数

type H

type H map[string]interface{}

响应数据包内容

func (H) MarshalXML

func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML allows type H to be used with xml.Marshal.

type ResponseBuilder

type ResponseBuilder struct {
	// HTTP 状态码
	HttpCode int
	// 业务状态码
	Code int
	// 状态码提示信息
	Message string
	// 响应内容信息
	Data H
	// 响应总时长
	ResponseTime time.Duration
	// 响应格式
	Format string
}

构建响应结构体

func (*ResponseBuilder) GetCode

func (response *ResponseBuilder) GetCode() int

func (*ResponseBuilder) GetData

func (response *ResponseBuilder) GetData() H

func (*ResponseBuilder) GetFormat

func (response *ResponseBuilder) GetFormat() string

func (*ResponseBuilder) GetHttpCode

func (response *ResponseBuilder) GetHttpCode() int

func (*ResponseBuilder) GetMessage

func (response *ResponseBuilder) GetMessage() string

func (*ResponseBuilder) GetResponseTime

func (response *ResponseBuilder) GetResponseTime() time.Duration

func (*ResponseBuilder) WithCode

func (response *ResponseBuilder) WithCode(code int) *ResponseBuilder

func (*ResponseBuilder) WithData

func (response *ResponseBuilder) WithData(data H) *ResponseBuilder

func (*ResponseBuilder) WithFormat

func (response *ResponseBuilder) WithFormat(format string) *ResponseBuilder

func (*ResponseBuilder) WithHttpCode

func (response *ResponseBuilder) WithHttpCode(code int) *ResponseBuilder

func (*ResponseBuilder) WithMessage

func (response *ResponseBuilder) WithMessage(message string) *ResponseBuilder

func (*ResponseBuilder) WithResponseTime

func (response *ResponseBuilder) WithResponseTime(duration time.Duration) *ResponseBuilder

Jump to

Keyboard shortcuts

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