From 2eee8baa26ab9d86a6b03c9dcb7c36e1cd13ee46 Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Sat, 17 Oct 2020 12:47:45 +0100 Subject: [PATCH] store http state --- storage/http.go | 34 ++++++++++++++++++++++++++++++++++ storage/storage.go | 6 ++++++ 2 files changed, 40 insertions(+) create mode 100644 storage/http.go diff --git a/storage/http.go b/storage/http.go new file mode 100644 index 0000000..09a589b --- /dev/null +++ b/storage/http.go @@ -0,0 +1,34 @@ +package storage + +type HTTPState struct { + LastModified string + Etag string +} + +func (s *Storage) GetHTTPState(url string) *HTTPState { + row := s.db.QueryRow(` + select last_modified, etag + from http_state where url = ? + `, url) + + if row == nil { + return nil + } + + var state HTTPState + row.Scan(&state.LastModified, &state.Etag) + return &state +} + +func (s *Storage) SetHTTPState(url string, state HTTPState) { + _, err := s.db.Exec(` + insert into http_state (url, last_modified, etag) + values (?, ?, ?) + on conflict (url) do update set last_modified = ?, etag = ?`, + url, state.LastModified, state.Etag, + state.LastModified, state.Etag, + ) + if err != nil { + s.log.Print(err) + } +} diff --git a/storage/storage.go b/storage/storage.go index ea64da9..758084f 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -61,6 +61,12 @@ create virtual table if not exists search using fts4(title, description, content create trigger if not exists del_item_search after delete on items begin delete from search where rowid = old.search_rowid; end; + +create table if not exists http_state ( + url string not null primary key, + last_modified string not null, + etag string not null +); ` type Storage struct {