Documentation
¶
Index ¶
- func Middleware(service *OperationLogService, logger logging.Logger) func(next http.Handler) http.Handler
- func NewOperationLogModule(logger logging.Logger, deps *core.Dependencies) core.Module
- type ClearInput
- type CreateLogInput
- type LogQueryInput
- type OperationLogHandler
- type OperationLogModule
- type OperationLogService
- func (s *OperationLogService) ClearOldLogs(ctx context.Context, retentionDays int) (int, error)
- func (s *OperationLogService) Create(input *CreateLogInput)
- func (s *OperationLogService) Delete(ctx context.Context, id uuid.UUID) error
- func (s *OperationLogService) List(ctx context.Context, input *LogQueryInput) ([]*ent.OperationLog, int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(service *OperationLogService, logger logging.Logger) func(next http.Handler) http.Handler
Middleware 创建操作日志记录中间件
func NewOperationLogModule ¶
NewOperationLogModule creates a new operation log module
Types ¶
type ClearInput ¶
type ClearInput struct {
RetentionDays int `json:"retentionDays"`
}
ClearInput defines parameters for clearing logs
type CreateLogInput ¶
type CreateLogInput struct {
RequestID string
Method string
Path string
QueryParams string
Body string
Status int
Latency int64
ClientIP string
UserAgent string
ErrorMessage string
UserID *uuid.UUID
OwnerDomainID *uuid.UUID
}
CreateLogInput 创建日志输入参数
type LogQueryInput ¶
type LogQueryInput struct {
Page int
PageSize int
StartDate *time.Time
EndDate *time.Time
Method string
Path string
Status *int
UserID *uuid.UUID
ClientIP string
RequestID string
}
LogQueryInput 查询参数
type OperationLogHandler ¶
type OperationLogHandler struct {
// contains filtered or unexported fields
}
func NewOperationLogHandler ¶
func NewOperationLogHandler(service *OperationLogService, logger logging.Logger) *OperationLogHandler
func (*OperationLogHandler) Clear ¶
func (h *OperationLogHandler) Clear(w http.ResponseWriter, r *http.Request)
Clear deletes old logs @Summary Clear old operation logs @Tags Logs @Accept json @Produce json @Param request body ClearInput true "Retention settings" @Success 200 {object} responder.Response @Router /logs/operations/clear [post]
func (*OperationLogHandler) Delete ¶
func (h *OperationLogHandler) Delete(w http.ResponseWriter, r *http.Request)
Delete deletes a single log entry @Summary Delete operation log @Tags Logs @Param id path string true "Log ID" @Success 200 {object} responder.Response @Router /logs/operations/{id} [delete]
func (*OperationLogHandler) List ¶
func (h *OperationLogHandler) List(w http.ResponseWriter, r *http.Request)
List returns a list of operation logs @Summary List operation logs @Tags Logs @Accept json @Produce json @Param page query int false "Page number" @Param pageSize query int false "Page size" @Param method query string false "HTTP Method" @Param status query int false "HTTP Status" @Param startDate query string false "Start date (RFC3339)" @Param endDate query string false "End date (RFC3339)" @Success 200 {object} responder.Response @Router /logs/operations [get]
type OperationLogModule ¶
type OperationLogModule struct {
// contains filtered or unexported fields
}
OperationLogModule manages the operation log module
func (*OperationLogModule) Middleware ¶
Middleware returns the operation logging middleware
func (*OperationLogModule) Name ¶
func (m *OperationLogModule) Name() string
func (*OperationLogModule) RegisterPrivateRoutes ¶
func (m *OperationLogModule) RegisterPrivateRoutes(r chi.Router)
RegisterPrivateRoutes registers protected operation log endpoints
func (*OperationLogModule) RegisterPublicRoutes ¶
func (m *OperationLogModule) RegisterPublicRoutes(r chi.Router)
RegisterPublicRoutes registers public operation log endpoints (none)
type OperationLogService ¶
type OperationLogService struct {
// contains filtered or unexported fields
}
func NewOperationLogService ¶
func NewOperationLogService(client *ent.Client, logger logging.Logger) *OperationLogService
func (*OperationLogService) ClearOldLogs ¶
ClearOldLogs deletes logs older than retention days
func (*OperationLogService) Create ¶
func (s *OperationLogService) Create(input *CreateLogInput)
Create Asynchronously creates an operation log We use a separate context or background context to ensure log is saved even if request context is cancelled
func (*OperationLogService) List ¶
func (s *OperationLogService) List(ctx context.Context, input *LogQueryInput) ([]*ent.OperationLog, int, error)
List queries operation logs with filters