forked from dcjones/mk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
remote.go
56 lines (50 loc) · 1.13 KB
/
remote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"net/http"
"net/url"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
// for files that are http(s) urls, use the Last-Modified header
func updateHttpTimestamp(u *node) {
resp, err := http.Head(u.name)
if err != nil {
log.Fatal(err)
}
lastModified := resp.Header.Get("Last-Modified")
if lastModified == "" {
// no Last-Modified header so lets assume that it
// is very old - but still exists
u.t = time.Unix(0, 0)
u.exists = true
u.flags |= nodeFlagProbable
} else {
tmptime, err := time.Parse(time.RFC1123, lastModified)
if err != nil {
log.Fatal(err)
}
u.t = tmptime
u.exists = true
u.flags |= nodeFlagProbable
}
}
func updateS3Timestamp(u *node, uri *url.URL) {
svc := s3.New(session.New())
input := &s3.HeadObjectInput{
Bucket: aws.String(uri.Host),
Key: aws.String(uri.Path[1:]),
}
result, err := svc.HeadObject(input)
if err != nil {
u.t = time.Unix(0, 0)
u.exists = false
} else {
u.t = *result.LastModified
u.exists = true
}
u.flags |= nodeFlagProbable
//fmt.Println(result)
}