mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 10:42:45 +08:00
Add classification annotations
This commit is contained in:
@@ -9,6 +9,10 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 常量定义
|
||||
// ============================================================================
|
||||
|
||||
const (
|
||||
CSRFTokenLength = 32
|
||||
CSRFCookieName = "csrf_token"
|
||||
@@ -16,6 +20,10 @@ const (
|
||||
CSRFFormField = "csrf_token"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
// 私有函数
|
||||
// ============================================================================
|
||||
|
||||
// generateRandomBytes 生成指定长度的随机字节
|
||||
func generateRandomBytes(length int) ([]byte, error) {
|
||||
bytes := make([]byte, length)
|
||||
@@ -26,6 +34,10 @@ func generateRandomBytes(length int) ([]byte, error) {
|
||||
return bytes, nil
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 公共函数
|
||||
// ============================================================================
|
||||
|
||||
// GenerateCSRFToken 生成CSRF令牌
|
||||
func GenerateCSRFToken() (string, error) {
|
||||
bytes, err := generateRandomBytes(CSRFTokenLength)
|
||||
@@ -190,4 +202,4 @@ func CSRFTokenHandler(c *gin.Context) {
|
||||
"csrf_token": token,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user