-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (41 loc) · 1.31 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
// GLOBO A micro service that helps the transition from lat/long based system to google's S2
// 2016 giulio <[email protected]>
package main
import (
"fmt"
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/giulioungaretti/globo/counts"
"github.com/giulioungaretti/globo/geoJSON"
"github.com/giulioungaretti/globo/middleware"
"github.com/giulioungaretti/globo/pip"
"github.com/giulioungaretti/globo/point"
"github.com/justinas/alice"
)
func main() {
defaultMiddleware := alice.New(middleware.TimeOut, middleware.IsJSON, middleware.PostOnly)
// point
pointHandler := http.HandlerFunc(point.Handler)
http.Handle("/tos2/point", defaultMiddleware.Then(pointHandler))
// geojson
geoJSONHandler := http.HandlerFunc(geoJSON.Handler)
http.Handle(geoJSON.Endpoint, defaultMiddleware.Then(geoJSONHandler))
// pip
contains := http.HandlerFunc(pip.Handler)
http.Handle("/contains", defaultMiddleware.Then(contains))
// query
count := http.HandlerFunc(counts.Handler)
http.Handle(counts.Endpoint, count)
// server
port := os.Getenv("PORT")
lvl, err := ParseLogLevel(os.Getenv("LOGLEVEL"))
if err != nil {
panic(err)
}
log.SetLevel(lvl)
//addr := fmt.Sprintf("10.0.1.3:%v", port)
addr := fmt.Sprintf(":%v", port)
log.Debugf(" 🌎 listening: %v 🌎 ", addr)
http.ListenAndServe(addr, nil)
}