middleware

package
v1.32.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  = 1
	KB = 1024 * B
	MB = 1024 * KB
	GB = 1024 * MB
)
View Source
const DownloadUrlPrefix = "/public/downloadFile/"

Variables

View Source
var CasbinExclude = []UrlInfo{
	{Url: "/api/v1/dict/type-option-select", Method: "GET"},
	{Url: "/api/v1/dict-data/option-select", Method: "GET"},

	{Url: "/api/v1/deptTree", Method: "GET"},

	{Url: "/api/v1/menu-role", Method: "GET"},

	{Url: "/api/v1/configKey/:configKey", Method: "GET"},
	{Url: "/api/v1/app-config", Method: "GET"},

	{Url: "/api/v1/getinfo", Method: "GET"},
	{Url: "/api/v1/user/profile", Method: "GET"},
	{Url: "/api/v1/user/avatar", Method: "POST"},
	{Url: "/api/v1/user/pwd", Method: "PUT"},
	{Url: "/api/v1/user/status", Method: "PUT"},

	{Url: "/api/v1/roleMenuTreeSelect/:roleId", Method: "GET"},
	{Url: "/api/v1/roleDeptTreeSelect/:roleId", Method: "GET"},
	{Url: "/api/v1/public/uploadFile", Method: "POST"},

	{Url: "/api/v1/captcha", Method: "GET"},
	{Url: "/api/v1/login", Method: "POST"},
	{Url: "/api/v1/logout", Method: "POST"},
	{Url: "/api/v1/refresh_token", Method: "GET"},
	{Url: "/metrics", Method: "GET"},
	{Url: "/health", Method: "GET"},
	{Url: "/", Method: "GET"},
	{Url: "/info", Method: "GET"},
	{Url: "/server-monitor", Method: "GET"},
}

CasbinExclude casbin 排除的路由列表

Functions

func AuthCheckRole

func AuthCheckRole() gin.HandlerFunc

AuthCheckRole 权限检查中间件

func AuthInit

func AuthInit() (*jwt.GinJWTMiddleware, error)

AuthInit jwt验证new

func CustomError

func CustomError(c *gin.Context)

func GenerateCaptchaHandler

func GenerateCaptchaHandler(c *gin.Context)

GenerateCaptchaHandler 获取验证码 @Summary 获取验证码 @Description 获取验证码 @Tags 登陆 @Success 200 {object} response.Response{data=string,id=string,msg=string} "{"code": 200, "data": [...]}" @Router /api/v1/captcha [get]

func GetHourDiffer

func GetHourDiffer(startTime, endTime string) int64

获取相差时间

func GinWrapper

func GinWrapper(handler http.Handler) gin.HandlerFunc

GinWrapper http.Handler 转换成 gin.HandlerFunc

func InitMiddleware

func InitMiddleware(r *gin.Engine)

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

LoggerToFile 日志记录到文件

func Metrics

func Metrics() gin.HandlerFunc

Metrics returns a Gin measuring middleware.

func NoCache

func NoCache(c *gin.Context)

NoCache is a middleware function that appends headers to prevent the client from caching the HTTP response.

func Options

func Options(c *gin.Context)

Options is a middleware function that appends headers for options requests and aborts then exits the middleware chain and ends the request.

func Ping

func Ping(c *gin.Context)

func RequestId

func RequestId(trafficKey string) gin.HandlerFunc

RequestId 自动增加requestId, 设置 logger

func Secure

func Secure(c *gin.Context)

Secure is a middleware function that appends security and resource access headers.

func Sentinel

func Sentinel() gin.HandlerFunc

Sentinel 限流

func ServerInfo

func ServerInfo(custom func(ret map[string]interface{}) map[string]interface{}) gin.HandlerFunc

ServerInfo 获取系统信息 @Summary 系统信息 @Description 获取JSON @Tags 系统信息 @Success 200 {object} response.Response "{"code": 200, "data": [...]}" @Router /server-monitor [get] @Security Bearer

func SetDBOperLog

func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string, reqMethod string, latencyTime time.Duration, body string, result string, apiCode int)

SetDBOperLog 写入操作日志表 fixme 该方法后续即将弃用

func TlsHandler

func TlsHandler() gin.HandlerFunc

func Trace

func Trace() gin.HandlerFunc

Trace 链路追踪

func WithContextDb

func WithContextDb(c *gin.Context)

Types

type File

type File struct {
	api.Api
}

func (File) DownloadFile added in v1.0.20

func (e File) DownloadFile(c *gin.Context)

DownloadFile 下载文件 @Summary 下载文件 @Description 下载文件 @Tags 公共接口 @Param pathname path string true "pathname" @Param filename path string true "filename" @Param as query string true "as" @Success 200 @Failure 503 @Success 200 {object} response.Response "{"code": 200, "data": [...]}" @Router /public/downloadFile/{pathname}/{filename} [get] @Security Bearer

func (File) ImportTempFile added in v1.0.20

func (e File) ImportTempFile(c *gin.Context) (*FileResponse, error)

ImportTempFile upload a temp file

func (File) UploadFile

func (e File) UploadFile(c *gin.Context)

UploadFile 上传图片 @Summary 上传图片 @Description 获取JSON @Tags 公共接口 @Accept multipart/form-data @Param type query string true "type" (1:单图,2:多图, 3:base64图片) @Param file formData file true "file" @Success 200 {string} string "{"code": 200, "message": "添加成功"}" @Success 200 {string} string "{"code": -1, "message": "添加失败"}" @Router /api/v1/public/uploadFile [post] @Security Bearer

type FileResponse

type FileResponse struct {
	Path     string `json:"path"`
	FullPath string `json:"full_path"`
	Name     string `json:"name"`
	Size     int64  `json:"size"`
}

type PresignToken added in v1.0.32

type PresignToken struct {
	api.Api
}

func (PresignToken) PresignToken added in v1.0.35

func (e PresignToken) PresignToken(c *gin.Context)

PresignToken 预签名令牌 @Summary 预签名令牌 @Description 预签名令牌 @Tags 公共接口 @Param data body PresignTokenRequest true "data" @Failure 500 @Success 200 {object} PresignTokenResponse "{"code": 200, "data": [...]}" @Router /presign-token [post] @Security Bearer

type PresignTokenRequest added in v1.0.32

type PresignTokenRequest struct {
	Directory string `json:"directory"`
	Filename  string `json:"filename"`
	Duration  int    `json:"duration"`
}

type PresignTokenResponse added in v1.0.32

type PresignTokenResponse struct {
	Vendor string      `json:"vendor"`
	Token  interface{} `json:"token"`
}

type UrlInfo

type UrlInfo struct {
	Url    string
	Method string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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