ginHelper

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 10 Imported by: 0

README

gin 相关的方法,接口

统一接口输出
// ResponseJson 统一接口输出
type ResponseJson struct {
	Code      int64       `json:"code"`
	Msg       string      `json:"msg"`
	Date      interface{} `json:"data"`
	TimeStamp int64       `json:"timeStamp"`
}

统一接口输出方法

func APIOutPut(c *gin.Context, code int64, msg string, data interface{})


统一接口输出错误方法

func APIOutPutError(c *gin.Context, code int64, msg string)


获取参数

func GetPostArgs(c *gin.Context, obj interface{}) error


Documentation

Index

Constants

View Source
const (
	SuccessCode   int64 = 0
	ErrorCode     int64 = 1
	AuthErrorCode int64 = 403
)

Variables

View Source
var (
	CsrfName    = "cToken"
	CsrfAuthKey = "123456789"
)
View Source
var Router *gin.Engine

Functions

func APIOutPut

func APIOutPut(c *gin.Context, msg string, data interface{})

APIOutPut 统一接口输出方法

func APIOutPutError

func APIOutPutError(c *gin.Context, msg string)

APIOutPutError 统一接口输出错误方法

func AuthErrorOut

func AuthErrorOut(c *gin.Context)

AuthErrorOut 鉴权失败

func CSRFMiddleware

func CSRFMiddleware() gin.HandlerFunc

CSRFMiddleware use: ginHelper.CsrfName = "CsrfName" ginHelper.CsrfAuthKey = "CsrfAuthKey" Router.Use(ginHelper.CSRFMiddleware())

func CSRFTokenMiddleware

func CSRFTokenMiddleware() gin.HandlerFunc

func FormSetCSRF

func FormSetCSRF(r *http.Request) template.HTML

FormSetCSRF use:

c.HTML(http.StatusOK, "login.html", gin.H{
	"csrf": ginHelper.FormSetCSRF(c.Request),
})

func GetPostArgs

func GetPostArgs(c *gin.Context, obj interface{}) error

GetPostArgs 获取参数

func Handle

func Handle(h HandlerFunc) gin.HandlerFunc

func NewGinServer

func NewGinServer()

func OutHtml

func OutHtml()

func SetCSRFTokenMiddleware

func SetCSRFTokenMiddleware(key string) gin.HandlerFunc

Types

type GinCtx

type GinCtx struct {
	*gin.Context
}

GinCtx 给gin context 扩展方法

func (*GinCtx) APIOutPut

func (ctx *GinCtx) APIOutPut(data interface{}, msg string)

func (*GinCtx) APIOutPutError

func (ctx *GinCtx) APIOutPutError(err error, msg string)

func (*GinCtx) AuthErrorOut

func (ctx *GinCtx) AuthErrorOut()

AuthErrorOut 鉴权失败

func (*GinCtx) GetParam

func (ctx *GinCtx) GetParam(key string) string

func (*GinCtx) GetParamInt

func (ctx *GinCtx) GetParamInt(key string) int

func (*GinCtx) GetParamInt64

func (ctx *GinCtx) GetParamInt64(key string) int64

func (*GinCtx) GetPostArgs

func (ctx *GinCtx) GetPostArgs(obj interface{}) error

GetPostArgs 获取参数

func (*GinCtx) GetQuery

func (ctx *GinCtx) GetQuery(key string) string

func (*GinCtx) GetQueryInt

func (ctx *GinCtx) GetQueryInt(key string) int

func (*GinCtx) GetQueryInt64

func (ctx *GinCtx) GetQueryInt64(key string) int64

func (*GinCtx) PageList

func (ctx *GinCtx) PageList(pg, number, count, size int, urlTemp string) []*Page

PageList urlTemp = /a?pg=%d

func (*GinCtx) PageListInt

func (ctx *GinCtx) PageListInt(pg, number, count, size int) []int

type HandlerFunc

type HandlerFunc func(c *GinCtx)

type Page

type Page struct {
	Number int
	Action bool
	Url    string
}

type ResponseJson

type ResponseJson struct {
	Code      int64       `json:"code"` // succeed:0  err:1
	Msg       string      `json:"msg"`
	Date      interface{} `json:"data"`
	TimeStamp int64       `json:"timeStamp"`
}

ResponseJson 统一接口输出

Jump to

Keyboard shortcuts

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