完成任务3
This commit is contained in:
@@ -63,13 +63,15 @@ func SendErrorWithStatus(c echo.Context, httpStatus int, code ResponseCode, mess
|
||||
|
||||
// --- 带审计功能的响应函数 ---
|
||||
|
||||
// setAuditDetails 是一个内部辅助函数,用于在 echo.Context 中设置业务相关的审计信息。
|
||||
func setAuditDetails(c echo.Context, actionType, description string, targetResource interface{}) {
|
||||
// setAuditDetails 是一个内部辅助函数,用于在 echo.Context 中统一设置所有业务相关的审计信息。
|
||||
func setAuditDetails(c echo.Context, actionType, description string, targetResource interface{}, status models.AuditStatus, resultDetails string) {
|
||||
// 只有当 actionType 不为空时,才设置审计信息,这作为触发审计的标志
|
||||
if actionType != "" {
|
||||
c.Set(models.ContextAuditActionType.String(), actionType)
|
||||
c.Set(models.ContextAuditDescription.String(), description)
|
||||
c.Set(models.ContextAuditTargetResource.String(), targetResource)
|
||||
c.Set(models.ContextAuditStatus.String(), status)
|
||||
c.Set(models.ContextAuditResultDetails.String(), resultDetails)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +87,7 @@ func SendSuccessWithAudit(
|
||||
targetResource interface{}, // 审计目标资源,被操作的资源对象或其标识
|
||||
) error {
|
||||
// 1. 设置审计信息
|
||||
setAuditDetails(c, actionType, description, targetResource)
|
||||
setAuditDetails(c, actionType, description, targetResource, models.AuditStatusSuccess, "")
|
||||
// 2. 发送响应
|
||||
return SendResponse(c, code, message, data)
|
||||
}
|
||||
@@ -101,7 +103,7 @@ func SendErrorWithAudit(
|
||||
targetResource interface{}, // 审计目标资源,被操作的资源对象或其标识
|
||||
) error {
|
||||
// 1. 设置审计信息
|
||||
setAuditDetails(c, actionType, description, targetResource)
|
||||
setAuditDetails(c, actionType, description, targetResource, models.AuditStatusFailed, message)
|
||||
// 2. 发送响应
|
||||
return SendErrorResponse(c, code, message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user