This commit is contained in:
2026-08-15 01:58:41 +08:00
parent e55fb57432
commit 1a5969897a
32 changed files with 687 additions and 475 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin"
)
func AccessControl(runtime *conf.Runtime, access *service.AccessService, audit *service.AuditService) gin.HandlerFunc {
func AccessControl(runtime *conf.Runtime, access *service.AccessControlService, audit *service.AuditRecorder) gin.HandlerFunc {
return func(c *gin.Context) {
claims := Claims(c)
if claims == nil {
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"github.com/gin-gonic/gin"
)
func OperationAudit(runtime *conf.Runtime, service *service.AuditService) gin.HandlerFunc {
func OperationAudit(runtime *conf.Runtime, service *service.AuditRecorder) gin.HandlerFunc {
return func(c *gin.Context) {
path := c.Request.URL.Path
if !recordsOperation(c.Request.Method, path) {
+1 -1
View File
@@ -14,7 +14,7 @@ import (
// ErrorAudit supplies the database sink that the Error-level logging core
// provides. Expected authentication, permission and input failures are not
// system errors and therefore are not inserted into sys_error.
func ErrorAudit(audit *service.AuditService) gin.HandlerFunc {
func ErrorAudit(audit *service.AuditRecorder) gin.HandlerFunc {
return func(c *gin.Context) {
writer := &captureWriter{ResponseWriter: c.Writer, maxBytes: 1 << 20}
c.Writer = writer
+1 -1
View File
@@ -27,7 +27,7 @@ func SecurityRateLimit(settings *service.SecurityService) gin.HandlerFunc {
window = 60
}
key := "KRA_SecLimit" + c.ClientIP() + c.FullPath()
count, cacheErr := settings.CacheIncrement(c.Request.Context(), key, time.Duration(window)*time.Second)
count, cacheErr := settings.IncrementRateLimit(c.Request.Context(), key, time.Duration(window)*time.Second)
if cacheErr == nil && int(count) > config.LimitCount {
httpx.Fail(c, "请求太过频繁,请稍后再试")
c.Abort()
+1 -1
View File
@@ -16,7 +16,7 @@ import (
"github.com/gin-gonic/gin"
)
func Recovery(audit *service.AuditService, logger *slog.Logger) gin.HandlerFunc {
func Recovery(audit *service.AuditRecorder, logger *slog.Logger) gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
panicValue := recover()