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, 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` 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, 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 }