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:
@@ -40,7 +40,6 @@ func (p *NginxParser) Parse(eventCh <-chan Event, resultCh chan<- *storage.LogEn
|
|||||||
Path: &path,
|
Path: &path,
|
||||||
Status: &status,
|
Status: &status,
|
||||||
Method: &method,
|
Method: &method,
|
||||||
Reason: nil,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS requests (
|
|||||||
path TEXT,
|
path TEXT,
|
||||||
method TEXT,
|
method TEXT,
|
||||||
status TEXT,
|
status TEXT,
|
||||||
|
viewed BOOLEAN DEFAULT FALSE,
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
type LogEntry struct {
|
type LogEntry struct {
|
||||||
Service string
|
ID int `db:"id"`
|
||||||
IP string
|
Service string `db:"service"`
|
||||||
Path *string
|
IP string `db:"ip"`
|
||||||
Status *string
|
Path *string `db:"path"`
|
||||||
Method *string
|
Status *string `db:"status"`
|
||||||
Reason *string
|
Method *string `db:"method"`
|
||||||
|
IsViewed *bool `db:"viewed"`
|
||||||
|
CreatedAt string `db:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ban struct {
|
type Ban struct {
|
||||||
IP string
|
ID int `db:"id"`
|
||||||
Reason *string
|
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
|
method = *result.Method
|
||||||
}
|
}
|
||||||
|
|
||||||
reason := ""
|
|
||||||
if result.Reason != nil {
|
|
||||||
reason = *result.Reason
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := db.db.Exec(
|
_, 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.Service,
|
||||||
result.IP,
|
result.IP,
|
||||||
path,
|
path,
|
||||||
method,
|
method,
|
||||||
status,
|
status,
|
||||||
reason,
|
|
||||||
time.Now().Format(time.RFC3339),
|
time.Now().Format(time.RFC3339),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user