-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.go
More file actions
50 lines (37 loc) · 1006 Bytes
/
server.go
File metadata and controls
50 lines (37 loc) · 1006 Bytes
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 (
"encoding/json"
"fmt"
"net/http"
"go.uber.org/zap"
)
// Handlers
func deploymentState(w http.ResponseWriter, req *http.Request) {
bytes, err := json.Marshal(&state)
if err != nil {
panic("Json encoding issue: " + err.Error())
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if _, err := w.Write(bytes); err != nil {
panic("Write issue: " + err.Error())
}
}
func _health(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"health": "ok"}`)
}
// Http Server
func httpServer(port uint16, logger *zap.Logger) {
// Endpoints Handlers
http.HandleFunc("/deploymentstate", deploymentState)
http.HandleFunc("/_health", _health)
logger.Info("Starting HTTP Server",
zap.Uint16("port", port))
// Listener
err := http.ListenAndServe(fmt.Sprintf("%s:%d", "localhost", port), nil)
if err != nil {
panic("Error: " + err.Error())
}
}