@@ -58,7 +58,7 @@ func CreateResponseTables(db *sql.DB, tableNames ...string) error {
5858 url TEXT PRIMARY KEY,
5959 status INTEGER,
6060 body BLOB,
61- headers JSONB,
61+ header JSONB,
6262 timestamp DATETIME
6363 )` , tableName )
6464 _ , err := db .Exec (query )
@@ -85,7 +85,7 @@ func HttpToResponse(resp *http.Response) (*Response, error) {
8585}
8686
8787func getReaderQuery (tableName string ) string {
88- return fmt .Sprintf ("SELECT status, body, headers , timestamp FROM %s WHERE url = ?" , tableName )
88+ return fmt .Sprintf ("SELECT status, body, header , timestamp FROM %s WHERE url = ?" , tableName )
8989}
9090
9191func rowToResponse (row * sql.Row ) (* Response , error ) {
@@ -95,31 +95,31 @@ func rowToResponse(row *sql.Row) (*Response, error) {
9595 var (
9696 status int
9797 body string
98- headers string
98+ header string
9999 timestamp time.Time
100100 )
101- err := row .Scan (& status , & body , & headers , & timestamp )
101+ err := row .Scan (& status , & body , & header , & timestamp )
102102 if err != nil {
103103 return nil , fmt .Errorf ("scan response row: %w" , err )
104104 }
105- var headersMap map [string ][]string
106- json .Unmarshal ([]byte (headers ), & headersMap )
105+ var headerMap map [string ][]string
106+ json .Unmarshal ([]byte (header ), & headerMap )
107107
108108 return & Response {
109109 Status : status ,
110110 Body : io .NopCloser (strings .NewReader (body )),
111- Header : headersMap ,
111+ Header : headerMap ,
112112 Timestamp : timestamp ,
113113 }, nil
114114}
115115
116116func getWriterQuery (tableName string ) string {
117- return fmt .Sprintf (`INSERT INTO %s(url, status, body, headers , timestamp)
117+ return fmt .Sprintf (`INSERT INTO %s(url, status, body, header , timestamp)
118118 VALUES(?, ?, ?, ?, DATETIME('now'))
119119 ON CONFLICT(url) DO UPDATE SET
120120 status = ?,
121121 body = ?,
122- headers = ?,
122+ header = ?,
123123 timestamp = DATETIME('now')` , tableName )
124124}
125125
@@ -130,14 +130,14 @@ func execWriter(ctx context.Context, stmt *sql.Stmt, url string, resp *Response)
130130 }
131131 bodyStr := string (body )
132132
133- var headersBuf bytes.Buffer
134- json .NewEncoder (& headersBuf ).Encode (resp .Header )
135- headers := headersBuf .String ()
133+ var headerBuf bytes.Buffer
134+ json .NewEncoder (& headerBuf ).Encode (resp .Header )
135+ header := headerBuf .String ()
136136
137137 _ , err = stmt .ExecContext (ctx ,
138- url , resp .Status , bodyStr , headers ,
138+ url , resp .Status , bodyStr , header ,
139139 // On Conflict
140- resp .Status , bodyStr , headers )
140+ resp .Status , bodyStr , header )
141141
142142 if err != nil {
143143 return fmt .Errorf ("store response: %w" , err )
0 commit comments