mygin

package
v0.20.28 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CSRFCookieName = "nz-csrf"
	CSRFHeaderName = "X-CSRF-Token"
)

Variables

This section is empty.

Functions

func Authorize

func Authorize(opt AuthorizeOption) func(*gin.Context)

func BlockIfNotSuperAdmin added in v0.20.27

func BlockIfNotSuperAdmin(c *gin.Context, isPage bool) bool

BlockIfNotSuperAdmin 拒绝未登录或非超级管理员,返回 true 表示已拒绝并已写入响应。

func CSRFMiddleware added in v0.20.26

func CSRFMiddleware() gin.HandlerFunc

CSRFMiddleware CSRF 防护中间件(Double-Submit Cookie 模式) 对基于 Cookie 的 POST/PUT/DELETE/PATCH 请求校验 X-CSRF-Token 头与 CSRF Cookie 是否一致且签名有效

func ClearSessionCookies added in v0.20.26

func ClearSessionCookies(c *gin.Context)

ClearSessionCookies 清除认证与 CSRF Cookie

func CommonEnvironment

func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H

func CookieSecure added in v0.20.26

func CookieSecure(c *gin.Context) bool

CookieSecure 判断当前请求是否经 HTTPS 到达(直连 TLS 或反代 X-Forwarded-Proto)。 纯 HTTP 部署返回 false,不影响 Cookie 读写。

func GetPreferredTheme

func GetPreferredTheme(c *gin.Context, path string) string

func HashViewPassword added in v0.20.27

func HashViewPassword(password string) string

HashViewPassword generates the value stored in the view-password cookie. The process-local salt intentionally invalidates existing cookies on restart.

func PreferredTheme

func PreferredTheme(c *gin.Context)

func RecordPath

func RecordPath(c *gin.Context)

func RequireSuperAdmin added in v0.20.27

func RequireSuperAdmin() gin.HandlerFunc

RequireSuperAdmin 中间件:仅允许超级管理员访问。

func SafeRedirectPath added in v0.20.25

func SafeRedirectPath(c *gin.Context) string

SafeRedirectPath 从 Referer 解析同站相对路径用于跳转,失败则返回 "/"。

func SetCSRFCookie added in v0.20.26

func SetCSRFCookie(c *gin.Context)

SetCSRFCookie 在响应中设置 CSRF cookie(非 HttpOnly,JS 需读取)

func ShowErrorPage

func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool)

func ValidateViewPassword

func ValidateViewPassword(opt ValidateViewPasswordOption) gin.HandlerFunc

Types

type AuthorizeOption

type AuthorizeOption struct {
	GuestOnly  bool
	MemberOnly bool
	IsPage     bool
	AllowAPI   bool
	Msg        string
	Redirect   string
	Btn        string
}

type ErrInfo

type ErrInfo struct {
	Code  int
	Title string
	Msg   string
	Link  string
	Btn   string
}

type ValidateViewPasswordOption

type ValidateViewPasswordOption struct {
	IsPage        bool
	AbortWhenFail bool
}

Jump to

Keyboard shortcuts

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