mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-03 15:06:36 +08:00
416603b616
- Replace db.DB(ctx) with database.DB(ctx) from plugins/infra/database
- Replace db.Redis/db.PrefixedKey/db.GetJSON/db.SetJSON with cachepkg.* from plugins/infra/cache
- Replace pkg/persistence/idgen with pkg/idgen (already exists)
- Replace pkg/persistence/batchwriter with pkg/batchwriter (already exists)
- Replace pkg/persistence/migrator with pkg/migrator (already exists)
- Replace pkg/persistence/logstore with plugins/domain/risk_control/logstore
- Delete defunct pkg/{persistence,cap,message_gateway,push,shared,task}
- Fix vet issues: db alias in domain_test.go, driver_asynq_worker.TaskHandler reference
- Update Makefile architecture guard
- Update docs and skill references
- Update go.mod: gorilla/sessions promotion to direct dependency
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package logstore abstracts user access-log storage across ClickHouse, PostgreSQL and SQLite.
|
|
package logstore
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
userAccessLogTableName = "w_user_access_logs"
|
|
userAccessLogInsertColumns = "id, user_id, path, method, ip, user_agent, headers, status, latency, created_at"
|
|
)
|
|
|
|
// UserAccessLog stores HTTP access records in ClickHouse, PostgreSQL and SQLite.
|
|
type UserAccessLog struct {
|
|
ID uint64 `gorm:"column:id"`
|
|
UserID uint64 `gorm:"column:user_id"`
|
|
Path string `gorm:"column:path"`
|
|
Method string `gorm:"column:method"`
|
|
IP string `gorm:"column:ip"`
|
|
UserAgent string `gorm:"column:user_agent"`
|
|
Headers string `gorm:"column:headers"`
|
|
Status int32 `gorm:"column:status"`
|
|
Latency int64 `gorm:"column:latency"`
|
|
CreatedAt time.Time `gorm:"column:created_at"`
|
|
}
|
|
|
|
// TableName returns the table name.
|
|
func (UserAccessLog) TableName() string {
|
|
return userAccessLogTableName
|
|
}
|
|
|
|
// InsertColumns returns comma-separated column names for batch insert.
|
|
func (UserAccessLog) InsertColumns() string {
|
|
return userAccessLogInsertColumns
|
|
}
|
|
|
|
// BatchInsertSQL returns the INSERT prefix used by native batch writers.
|
|
func (UserAccessLog) BatchInsertSQL() string {
|
|
return fmt.Sprintf("INSERT INTO %s (%s)", userAccessLogTableName, userAccessLogInsertColumns)
|
|
}
|