Skip to content

Instantly share code, notes, and snippets.

@broady
Created December 5, 2016 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broady/d68192f04e3ff50bf9bf7e90ee879077 to your computer and use it in GitHub Desktop.
Save broady/d68192f04e3ff50bf9bf7e90ee879077 to your computer and use it in GitHub Desktop.
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