/
flickrit.go
44 lines (36 loc) · 935 Bytes
/
flickrit.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
package main
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/cors"
"github.com/martini-contrib/encoder"
"github.com/pboehm/flickrit/api"
"net/http"
)
func main() {
api := &api.API{
ApiKey: "122cc483be92bd806b696e7d458596ac",
DataCacheRenewalInterval: 15,
}
api.Setup()
go api.CyclicCacheRenewal()
m := martini.Classic()
m.Map(api)
m.Use(cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowCredentials: true,
}))
m.Use(func(c martini.Context, w http.ResponseWriter) {
c.MapTo(encoder.JsonEncoder{}, (*encoder.Encoder)(nil))
w.Header().Set("Content-Type", "application/json; charset=utf-8")
})
m.Get("/photos/:name", func(params martini.Params,
enc encoder.Encoder) (int, []byte) {
name, ok := params["name"]
if ok {
photos, _ := api.GetPhotosForUser(name)
return http.StatusOK, encoder.Must(enc.Encode(photos))
}
return 404, []byte("Not Found")
})
m.Run()
}