-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (31 loc) · 959 Bytes
/
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
package main
import (
"log"
"net/http"
)
// BuildID is set by CI
var BuildID string
func setServiceHeader(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Reply-Service", "namer-service")
if BuildID == "" {
w.Header().Set("X-Version", "dev")
} else {
w.Header().Set("X-Version", BuildID)
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Accept-Language, Content-Type, X-Version, X-Reply-Service")
if r.Method == "OPTIONS" {
return
}
h.ServeHTTP(w, r)
})
}
func main() {
globalmux := http.NewServeMux()
globalmux.HandleFunc("/", NameHandler)
globalmux.HandleFunc("/status/alive", AliveHandler)
globalmux.HandleFunc("/status/ready", HealthyHandler)
log.Fatal(http.ListenAndServe(":5003", setServiceHeader(globalmux)))
}