forked from KodujProCesko2018/trzni-rad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (43 loc) · 1.05 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
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
)
func ok(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "OK!")
}
func readGeoJSON(w http.ResponseWriter, r *http.Request) {
var (
content, err = ioutil.ReadFile("geo.json")
)
if err != nil {
log.Println("Non-existing file \"geo.json\"!")
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(content)
w.WriteHeader(http.StatusOK)
}
func registerMarket(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "TBD!")
}
func main() {
var (
muxer = http.NewServeMux()
host string
port int
)
flag.StringVar(&host, "host", "localhost", "Hostname to listen at (default localhost)")
flag.IntVar(&port, "port", 8080, "Port to listen to (default 8080)")
muxer.HandleFunc("/", ok)
muxer.HandleFunc("/geojson", readGeoJSON)
muxer.HandleFunc("/zadost", registerMarket)
listen := fmt.Sprintf("%s:%d", host, port)
log.Println("Listening at " + listen)
http.ListenAndServe(listen, muxer)
}