forked from fawick/go-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
36 lines (29 loc) · 903 Bytes
/
api.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
package maptiles
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
)
// NewTileLayer creates new tile layer.
func NewTileLayer(w http.ResponseWriter, r *http.Request) {
start := time.Now()
body, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if nil != err {
Ligneous.Critical(fmt.Sprintf("%v %v %v [500]", r.RemoteAddr, r.URL.Path, time.Since(start)))
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
api_request := new(ApiRequest)
err = json.Unmarshal(body, &api_request)
if nil != err {
Ligneous.Critical(fmt.Sprintf("%v %v %v [400]", r.RemoteAddr, r.URL.Path, time.Since(start)))
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Ligneous.Info(fmt.Sprintf("%v", api_request))
Ligneous.Info(fmt.Sprintf("%v %v %v [200]", r.RemoteAddr, r.URL.Path, time.Since(start)))
SendJsonResponseFromString(`{"status": "ok"}`, w, r)
}