1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:04:42 -07:00

cmd/tip: add App Engine Managed VM health check handler

Change-Id: I67826efaa3cb2883771837581dd95aa9ec3e6d2b
Reviewed-on: https://go-review.googlesource.com/18025
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Chris Broadfoot 2015-12-17 18:23:29 -08:00 committed by Brad Fitzpatrick
parent 9532e1006b
commit 4a5fb9938b

View File

@ -45,6 +45,7 @@ func main() {
p := &Proxy{builder: b}
go p.run()
http.Handle("/", p)
http.HandleFunc("/_ah/health", p.serveHealthCheck)
if err := http.ListenAndServe(":8080", nil); err != nil {
p.stop()
@ -106,6 +107,16 @@ func (p *Proxy) serveStatus(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "side=%v\ncurrent=%v\nerror=%v\n", p.side, p.cur, p.err)
}
func (p *Proxy) serveHealthCheck(w http.ResponseWriter, r *http.Request) {
p.mu.Lock()
defer p.mu.Unlock()
if p.proxy == nil {
http.Error(w, "not ready", 500)
return
}
io.WriteString(w, "ok")
}
// run runs in its own goroutine.
func (p *Proxy) run() {
p.side = "a"