-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (44 loc) · 1.01 KB
/
main.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
57
package main
import (
"log"
"net/http"
"os"
"time"
"strings"
"github.com/dimfeld/httptreemux"
"gopkg.in/mgo.v2"
)
type SearchResult struct {
URL string `json:"url"`
Snippet string `json:"snippet"`
Thumbnail string `json:"thumbnail"`
Context string `json:"context"`
}
type SearchResultResponse []SearchResult
type SearchQuery struct {
SearchID string `json:"-" bson:"search_id"`
Term string `json:"term" bson:"term"`
When time.Time `json:"when" bson:"when"`
}
type SearchQueryResponse []SearchQuery
func main() {
port := os.Getenv("PORT")
if !strings.Contains(port, ":") {
port = ":" + port
}
api := NewCustomSearchAPI()
masterDB, err := mgo.Dial(os.Getenv("MONGO_DSN"))
if err != nil {
log.Fatal(err)
}
h := Handlers{
api: api,
masterDB: masterDB,
}
r := httptreemux.New()
r.GET("/", h.Index)
r.GET("/api/imagesearch/:query", h.ImageSearch)
r.GET("/api/latest/imagesearch", h.Latest)
log.Printf("Listening on port %s\n", port)
http.ListenAndServe(port, r)
}