Fix: fix db migrations and add new row viewed
All checks were successful
CI.yml / build (push) Successful in 1m54s

This commit is contained in:
d3m0k1d
2026-01-13 18:22:15 +03:00
parent 5362761b82
commit 0421d9ef40
4 changed files with 14 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS requests (
path TEXT,
method TEXT,
status TEXT,
viewed BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

View File

@@ -1,15 +1,19 @@
package storage
type LogEntry struct {
Service string
IP string
Path *string
Status *string
Method *string
Reason *string
ID int `db:"id"`
Service string `db:"service"`
IP string `db:"ip"`
Path *string `db:"path"`
Status *string `db:"status"`
Method *string `db:"method"`
IsViewed *bool `db:"viewed"`
CreatedAt string `db:"created_at"`
}
type Ban struct {
IP string
Reason *string
ID int `db:"id"`
IP string `db:"ip"`
Reason *string `db:"reason"`
BannedAt string `db:"banned_at"`
}

View File

@@ -21,19 +21,13 @@ func Write(db *DB, resultCh <-chan *LogEntry) {
method = *result.Method
}
reason := ""
if result.Reason != nil {
reason = *result.Reason
}
_, err := db.db.Exec(
"INSERT INTO requests (service, ip, path, method, status, reason, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
"INSERT INTO requests (service, ip, path, method, status, created_at) VALUES (?, ?, ?, ?, ?, ?)",
result.Service,
result.IP,
path,
method,
status,
reason,
time.Now().Format(time.RFC3339),
)
if err != nil {