gin icon indicating copy to clipboard operation
gin copied to clipboard

request struct Supports custom filters

Open zh7314 opened this issue 8 months ago • 0 comments

Environment

github.com/gin-gonic/gin v1.9.1 windows

Description

I want to enter the gin framework in the request parameters, binding parameters can customize some operations, such as html escape, to avoid security problems, such as myFilter to do an encryption and decryption operation, did not find a solution

Example code

type AdminRequest struct {
	ID       int64  `form:"id" json:"id"`                                // 用户ID
	Name     string `form:"name" json:"name" filter:"html.EscapeString"` // 系统管理用户名
	Password string `form:"password" json:"password" filter:"myFilter"`  // 密码
	Page     int    `form:"page" json:"page"`                            // 页码
	PageSize int    `form:"pageSize" json:"pageSize"`                    // 页大小
}

like ‘json form use flag to get parameter name filter to customize some operations

zh7314 avatar Sep 17 '23 01:09 zh7314