Change response shape from redis_info endpoint

This commit is contained in:
Ken Hibino
2021-01-04 09:31:10 -08:00
parent 4951d2f571
commit 0c3cd80728
6 changed files with 42 additions and 8 deletions

View File

@@ -14,6 +14,11 @@ import (
// - http.Handler(s) for redis info related endpoints
// ****************************************************************************
type RedisInfoResponse struct {
Addr string `json:"address"`
Info map[string]string `json:"info"`
}
func newRedisInfoHandlerFunc(rdb *redis.Client) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
@@ -23,7 +28,11 @@ func newRedisInfoHandlerFunc(rdb *redis.Client) http.HandlerFunc {
return
}
info := parseRedisInfo(res)
if err := json.NewEncoder(w).Encode(info); err != nil {
resp := RedisInfoResponse{
Addr: redisAddr,
Info: info,
}
if err := json.NewEncoder(w).Encode(resp); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}