forked from martensson/vaban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
46 lines (41 loc) · 957 Bytes
/
services.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
package main
import (
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
func GetService(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
service := ps.ByName("service")
if s, ok := services[service]; ok {
err := r.JSON(w, http.StatusOK, s.Hosts)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, err = w.Write([]byte(err.Error()))
if err != nil {
log.Println(err)
}
}
return
} else {
w.WriteHeader(http.StatusNotFound)
_, err := w.Write([]byte("Service could not be found."))
if err != nil {
log.Println(err)
}
return
}
}
func GetServices(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
var keys []string
for k := range services {
keys = append(keys, k)
}
err := r.JSON(w, http.StatusOK, keys)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, err = w.Write([]byte(err.Error()))
if err != nil {
log.Println(err)
}
}
}