feat: recode NginxParser, add writer to db
All checks were successful
CI.yml / build (push) Successful in 1m54s

This commit is contained in:
d3m0k1d
2026-01-13 17:26:53 +03:00
parent b63da17043
commit 9767bb70f1
3 changed files with 64 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ type DB struct {
db *sql.DB
}
func NewDB(path string) (*DB, error) {
func NewDB() (*DB, error) {
db, err := sql.Open("sqlite3", "/var/lib/banforge/storage.db")
if err != nil {
return nil, err

View File

@@ -0,0 +1,43 @@
package storage
import (
"time"
)
func Write(db *DB, resultCh <-chan *LogEntry) {
for result := range resultCh {
path := ""
if result.Path != nil {
path = *result.Path
}
status := ""
if result.Status != nil {
status = *result.Status
}
method := ""
if result.Method != nil {
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 (?, ?, ?, ?, ?, ?, ?)",
result.Service,
result.IP,
path,
method,
status,
reason,
time.Now().Format(time.RFC3339),
)
if err != nil {
db.logger.Error("Failed to write to database", "error", err)
}
}
}