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:
6
auth.go
6
auth.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user