/
warmup.go
55 lines (48 loc) · 1.1 KB
/
warmup.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
package main
import (
"time"
"net/http"
"math/rand"
"github.com/labstack/echo"
"github.com/qedus/nds"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
)
func init() {
ah.Get("/warmup", warmupHandler)
}
func warmupHandler(c *echo.Context) error {
if appengine.IsDevAppServer() {
k := datastore.NewKey(c, "photo", "", 1, nil)
p := new(Photo)
err := nds.Get(c, k, p)
if err != datastore.ErrNoSuchEntity {
return c.NoContent(http.StatusOK)
}
photographers := []Photographer {
{1, "Mr Canon"},
{2, "Miss Nikon"},
{3, "Mrs Pentax"},
{4, "Ms Sony"},
}
// create some dummy data
var id int64
for m := 1; m <= 12; m++ {
for d := 1; d < 28; d++ {
taken := time.Date(2015, time.Month(m), d, 12, 0, 0, 0, time.UTC)
photographer := photographers[rand.Int31n(4)]
p = &Photo{
Photographer: photographer,
Uploaded : time.Now().UTC(),
Width : 8000,
Height : 6000,
Taken : taken,
}
id++
k = datastore.NewKey(c, "photo", "", id, nil)
nds.Put(c, k, p)
}
}
}
return c.NoContent(http.StatusOK)
}