-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
51 lines (43 loc) · 1.02 KB
/
server.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
package main
import (
"fmt"
"github.com/golang/glog"
"github.com/gorilla/mux"
"github.com/hokkaido/blink"
_ "github.com/hokkaido/blink-mbtiles"
"net/http"
_ "net/url"
"strconv"
)
func defaultHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func tileHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
//path, _ := vars["path"]
zoom, _ := strconv.Atoi(vars["zoom"])
x, _ := strconv.Atoi(vars["x"])
y, _ := strconv.Atoi(vars["y"])
layer, err := blink.GetLayer("moots")
if err != nil {
fmt.Fprintf(w, "Error: %s!", err)
}
if layer != nil {
tile, err := layer.GetTile(zoom, x, y)
if err != nil {
fmt.Fprintf(w, "Error: %s!", err)
}
w.Write(tile)
} else {
fmt.Fprintf(w, "Error: %s!", err)
}
}
func main() {
glog.Info("Startup...")
blink.Load("config.json")
r := mux.NewRouter()
r.HandleFunc("/", defaultHandler)
r.HandleFunc("/map/{path}/{zoom}/{x}/{y}", tileHandler)
http.Handle("/", r)
http.ListenAndServe(":3333", nil)
}