diff options
-rw-r--r-- | cache.go | 10 | ||||
-rw-r--r-- | http.go | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/cache.go b/cache.go index be00083..0967c11 100644 --- a/cache.go +++ b/cache.go @@ -3,7 +3,6 @@ package main import ( "errors" "io/ioutil" - "log" "strings" "sync" "time" @@ -52,7 +51,7 @@ func (cache *cacheWrapper) isFresh(path string) bool { // Wraps the two cache-checking functions. // One for /, the other for various requests. -func (cache *cacheWrapper) bap(requestPath string) { +func (cache *cacheWrapper) bap(requestPath string) error { var split []string var format, query string @@ -65,7 +64,7 @@ func (cache *cacheWrapper) bap(requestPath string) { cache.checkedInit(requestPath) if cache.isFresh(requestPath) { - return + return nil } var bytes []byte @@ -87,8 +86,7 @@ func (cache *cacheWrapper) bap(requestPath string) { } if err != nil { - log.Printf("Request error %s :: %s", requestPath, err.Error()) - bytes = []byte("Internal Error") + return err } cache.Lock() @@ -98,6 +96,8 @@ func (cache *cacheWrapper) bap(requestPath string) { raw: bytes, expires: time.Now().Add(cacheDuration), } + + return nil } // yoinks the raw data and expiry time to send to the requester diff --git a/http.go b/http.go index 8ef76c5..e67560c 100644 --- a/http.go +++ b/http.go @@ -22,8 +22,11 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { return } - cache.bap(r.URL.Path) - out, expires := cache.yoink(r.URL.Path) + err := cache.bap(r.URL.Path) + if err != nil { + errHTTP(w, r, err, http.StatusInternalServerError) + return + } if format == "json" { w.Header().Set("Content-Type", mimeJSON) @@ -31,9 +34,10 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", mimePlain) } + out, expires := cache.yoink(r.URL.Path) w.Header().Set("Expires", expires) - _, err := w.Write(out) + _, err = w.Write(out) if err != nil { errHTTP(w, r, err, http.StatusBadRequest) return |