in go/wsl/wsl.go [69:124]
func createHandler(hub http.Handler, downloadRoot string, shutdown func()) http.Handler {
handler := http.NewServeMux()
shutdownFunc := func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
httphelper.SetDefaultResponseHeaders(w.Header())
w.WriteHeader(http.StatusOK)
w.Write([]byte("shutting down"))
shutdown()
}
handler.HandleFunc("/quitquitquit", shutdownFunc)
handler.HandleFunc("/shutdown", shutdownFunc)
handler.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
httphelper.SetDefaultResponseHeaders(w.Header())
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
handler.Handle("/session", hub)
handler.Handle("/session/", hub)
handler.HandleFunc("/status", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
httphelper.SetDefaultResponseHeaders(w.Header())
w.WriteHeader(http.StatusOK)
respJSON := map[string]interface{}{
"status": 0,
"value": map[string]interface{}{
"build": map[string]interface{}{
"version": "unknown",
"revision": "unknown",
"time": "unknown",
},
"os": map[string]interface{}{
"arch": runtime.GOARCH,
"name": runtime.GOOS,
"version": "unknown",
},
"ready": true,
"message": "ready to create new sessions",
},
}
json.NewEncoder(w).Encode(respJSON)
})
handler.Handle("/google/staticfile/", http.StripPrefix("/google/staticfile/", http.FileServer(http.Dir(downloadRoot))))
return handler
}