fix: use sql.NullString for reason field in audit log

Update reason field handling in auth.go and db.go to properly support
NULL values using sql.NullString. When inserting expired temp entries
and serializing logs to JSON, extract the string value to avoid
JSON marshaling issues with nullable fields.
This commit is contained in:
db123-test
2026-05-04 17:48:18 +03:30
parent 6425158f61
commit a352adb441
2 changed files with 12 additions and 8 deletions

View File

@@ -182,8 +182,8 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc {
logs := make([]map[string]interface{}, 0)
for rows.Next() {
var ts time.Time
var action, apiClientIP, reason string
var ip, cidr sql.NullString
var action, apiClientIP string
var ip, cidr, reason sql.NullString
var ttlSeconds sql.NullInt64
if err := rows.Scan(&ts, &action, &ip, &cidr, &ttlSeconds, &reason, &apiClientIP); err != nil {
continue
@@ -192,7 +192,7 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc {
"timestamp": ts,
"action": action,
"api_client_ip": apiClientIP,
"reason": reason,
"reason": reason.String,
}
if ip.Valid {
entry["ip"] = ip.String