mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
528240026d
- make format 现在与 code-check 使用同一格式化器(golangci-lint fmt),消除 goimports -local 与 gofumpt 的格式拉锯 - .golangci.yml 关闭默认 50/3 截断,完整上报所有问题(只增强不弱化) - 全库 gofumpt 规范化(203 files, 纯格式无行为变更)
38 lines
966 B
Go
38 lines
966 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package auth
|
|
|
|
import (
|
|
"Wavelet/core/contracts"
|
|
"Wavelet/pkg/logger"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// LogForAudit 将登录鉴权审计日志写入 Logger
|
|
func LogForAudit(ctx context.Context, user *contracts.UserDTO, c *gin.Context) {
|
|
if user == nil || c == nil {
|
|
return
|
|
}
|
|
auditLog := loginRequiredAuditLog{
|
|
UserID: user.ID,
|
|
Username: user.Username,
|
|
ClientIP: c.ClientIP(),
|
|
Method: c.Request.Method,
|
|
Path: c.Request.URL.Path,
|
|
RequestURI: c.Request.RequestURI,
|
|
UserAgent: c.Request.UserAgent(),
|
|
Referer: c.Request.Referer(),
|
|
}
|
|
auditJSON, err := json.Marshal(auditLog)
|
|
if err != nil {
|
|
logger.ErrorF(ctx, "[LoginRequiredAudit] marshal failed: %v", err)
|
|
logger.DebugF(ctx, "[LoginRequiredAudit] %s %d %s", c.ClientIP(), user.ID, user.Username)
|
|
} else {
|
|
logger.DebugF(ctx, "[LoginRequiredAudit] %s", auditJSON)
|
|
}
|
|
}
|