process-fastly-logs/models/log_entry.go

86 lines
1.9 KiB
Go
Raw Permalink Normal View History

2025-01-04 20:47:32 +00:00
package models
import (
"time"
"git.resf.org/infrastructure/process-fastly-logs/db"
)
type LogEntry struct {
Priority int
Timestamp time.Time
RequestTime time.Time
CacheServer string
ServiceID string
ClientIP string
RequestMethod string
RequestURL string
Protocol string
ResponseStatus int
ResponseBodyBytes int
Host string
UserAgent string
Datacenter string
GeoCity string
GeoContinentCode string
GeoRegion string
StartTime time.Time
ElapsedTimeUsec int
IsHit bool
CacheResult string
}
func (entry *LogEntry) Save() error {
insertSQL := `INSERT INTO logs(
priority,
timestamp,
cache_server,
service_id,
client_ip,
request_method,
request_time,
2025-01-04 20:47:32 +00:00
request_url,
protocol,
response_status,
response_body_bytes,
host,
user_agent,
datacenter,
geo_city,
geo_continent_code,
geo_region,
start_time,
elapsed_time_usec,
is_hit,
cache_result
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
2025-01-04 20:47:32 +00:00
statement, err := db.DB.Prepare(insertSQL)
if err != nil {
return err
}
_, err = statement.Exec(
entry.Priority,
entry.Timestamp,
entry.CacheServer,
entry.ServiceID,
entry.ClientIP,
entry.RequestMethod,
entry.RequestTime,
2025-01-04 20:47:32 +00:00
entry.RequestURL,
entry.Protocol,
entry.ResponseStatus,
entry.ResponseBodyBytes,
entry.Host,
entry.UserAgent,
entry.Datacenter,
entry.GeoCity,
entry.GeoContinentCode,
entry.GeoRegion,
entry.StartTime,
entry.ElapsedTimeUsec,
entry.IsHit,
entry.CacheResult,
)
return err
}