Created
December 5, 2016 21:55
-
-
Save broady/d68192f04e3ff50bf9bf7e90ee879077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
"time" | |
) | |
var startup = time.Now() | |
func main() { | |
http.HandleFunc("/healthz", health) | |
http.HandleFunc("/", serve) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func serve(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "since startup: %s\n", time.Now().Sub(startup)) | |
for _, e := range os.Environ() { | |
fmt.Fprintln(w, e) | |
} | |
} | |
func health(w http.ResponseWriter, r *http.Request) { | |
if time.Now().After(startup.Add(30 * time.Second)) { | |
io.WriteString(w, "ok") | |
return | |
} | |
http.Error(w, "starting up", http.StatusServiceUnavailable) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment