2021-10-07 15:23:34 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/ebosas/microservices/internal/cache"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
)
|
|
|
|
|
2021-10-10 17:49:39 +02:00
|
|
|
// handleAPICache handles API calls for cached messages.
|
2021-10-07 15:23:34 +02:00
|
|
|
func handleAPICache(cr *redis.Client) func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
data, err := cache.GetCacheJSON(cr)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
2021-10-10 17:49:39 +02:00
|
|
|
w.Write([]byte("500 – Something went wrong"))
|
2021-10-07 15:23:34 +02:00
|
|
|
|
|
|
|
log.Printf("get cache json: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
fmt.Fprint(w, data)
|
|
|
|
}
|
|
|
|
}
|