From e82d9d49fb8878e5e427168c0aec7592c02c0329 Mon Sep 17 00:00:00 2001 From: Jordan Olshevski Date: Sun, 3 Mar 2024 19:37:32 -0600 Subject: [PATCH] Avoid 412 responses --- main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 80fb8ed..76da413 100644 --- a/main.go +++ b/main.go @@ -29,11 +29,14 @@ func main() { } router := httprouter.New() + cache := newCache(k) router.GET("/healthz", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + if c, _ := cache.Load(); c == nil { + w.WriteHeader(500) // wait for cache to warm before accepting requests + } w.WriteHeader(204) }) - cache := newCache(k) router.GET("/v1/fobs", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { if wait := r.URL.Query().Get("wait"); wait != "" { waitDuration, err := time.ParseDuration(wait) @@ -45,10 +48,6 @@ func main() { } users, hash := cache.Load() - if users == nil { - w.WriteHeader(412) - return - } if hash != "" && hash == r.Header.Get("If-None-Match") { w.WriteHeader(304) return