Fix: fix db migrations and add new row viewed
All checks were successful
CI.yml / build (push) Successful in 1m54s
All checks were successful
CI.yml / build (push) Successful in 1m54s
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user