mirror of
https://github.com/vbatts/sl-feeds.git
synced 2025-06-30 06:08:29 +00:00
*: prepare for time comparison with remote
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
c5585b2c1d
commit
871ba61aa1
2 changed files with 66 additions and 3 deletions
|
@ -13,10 +13,38 @@ type Repo struct {
|
|||
URL string
|
||||
}
|
||||
|
||||
func (r Repo) head(file string) (*http.Response, error) {
|
||||
return http.Head(r.URL + "/" + file)
|
||||
}
|
||||
func (r Repo) get(file string) (*http.Response, error) {
|
||||
return http.Get(r.URL + "/" + file)
|
||||
}
|
||||
|
||||
func (r Repo) NewerChangeLog(than time.Time) (e []changelog.Entry, mtime time.Time, err error) {
|
||||
resp, err := r.head("ChangeLog.txt")
|
||||
if err != nil {
|
||||
return nil, time.Unix(0, 0), err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, time.Unix(0, 0), fmt.Errorf("%d status from %s", resp.StatusCode, resp.Request.URL)
|
||||
}
|
||||
|
||||
mtime, err = http.ParseTime(resp.Header.Get("last-modified"))
|
||||
if err != nil {
|
||||
return nil, time.Unix(0, 0), err
|
||||
}
|
||||
|
||||
if mtime.After(than) {
|
||||
return r.ChangeLog()
|
||||
}
|
||||
return nil, time.Unix(0, 0), NotNewer
|
||||
}
|
||||
|
||||
// NotNewer is a status error usage to indicate that the remote file is not newer
|
||||
var NotNewer = fmt.Errorf("Remote file is not newer than provided time")
|
||||
|
||||
// ChangeLog fetches the ChangeLog.txt for this remote Repo, along with the
|
||||
// last-modified (for comparisons).
|
||||
func (r Repo) ChangeLog() (e []changelog.Entry, mtime time.Time, err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue