store http state

This commit is contained in:
Nazar Kanaev 2020-10-17 12:47:45 +01:00
parent 0949ffc027
commit 2eee8baa26
2 changed files with 40 additions and 0 deletions

34
storage/http.go Normal file
View File

@ -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)
}
}

View File

@ -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 create trigger if not exists del_item_search after delete on items begin
delete from search where rowid = old.search_rowid; delete from search where rowid = old.search_rowid;
end; 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 { type Storage struct {