diff options
author | Ty Davis <tydavis@gmail.com> | 2016-06-01 16:18:20 -0700 |
---|---|---|
committer | Ty Davis <tydavis@gmail.com> | 2016-06-01 16:18:20 -0700 |
commit | 541ea79508687b4da67b3d0e386b65b14a0177f2 (patch) | |
tree | 532e0d23814075bafc8ed22e5de9a68154c23ef2 | |
download | show-readiness-541ea79508687b4da67b3d0e386b65b14a0177f2.tar.gz show-readiness-541ea79508687b4da67b3d0e386b65b14a0177f2.zip |
Not yet ready
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | main.go | 61 |
2 files changed, 62 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e92f57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags @@ -0,0 +1,61 @@ +package main + +import ( + "log" + "net/http" + "os" + "time" + + "github.com/facebookgo/httpdown" +) + +var ReadyValue = http.StatusOK +var LiveValue = http.StatusOK +var hostname string + +func readinessCheck(w http.ResponseWriter, r *http.Request) { + w.Header().Set("responding-pod", hostname) + http.Error(w, "", ReadyValue) +} + +func livenessCheck(w http.ResponseWriter, r *http.Request) { + w.Header().Set("responding-pod", hostname) + http.Error(w, "", LiveValue) +} + +func rootHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("responding-pod", hostname) + w.Fprintf(w, "%s", "I'm serving traffic!") +} + +func main() { + // Force log output to stdout for Docker + log.SetOutput(os.Stdout) + // Delay for startup + time.Sleep(1 * time.Second) + hostname, _ = os.Hostname() + + log.Println("Service started on port 80") + + mux := http.NewServeMux() + mux.HandleFunc("/", rootHandler) + mux.HandleFunc("/ping", livenessCheck) + mux.HandleFunc("/ready", readinessCheck) + mux.HandleFunc("/makeNotReady", makeNotReady) + mux.HandleFunc("/makePodReady", makePodReady) + + server := &http.Server{ + Addr: ":80", + Handler: mux, + } + + hd := &httpdown.HTTP{ + StopTimeout: 10 * time.Second, + KillTimeout: 1 * time.Second, + } + + if err := httpdown.ListenAndServe(server, hd); err != nil { + log.Fatalln(err) + } + +} |