From 0244a3811ec8b8e11e556521cbcb4e9f2a1cbe5d Mon Sep 17 00:00:00 2001
From: Yordan Kinkov <yordan.kinkov@vereign.com>
Date: Tue, 5 Apr 2022 14:17:09 +0300
Subject: [PATCH] #3 change GET endpoint response type to json

---
 design/design.go                  | 4 ++--
 internal/clients/redis/client.go  | 4 ++--
 internal/service/cache/service.go | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/design/design.go b/design/design.go
index 5ac91e8..1b8d82d 100644
--- a/design/design.go
+++ b/design/design.go
@@ -41,10 +41,10 @@ var _ = Service("cache", func() {
 	Description("Cache service allows storing and retrieving data from distributed cache.")
 
 	Method("Get", func() {
-		Description("Get value from the cache. The result is a sequence of bytes which the client must decode.")
+		Description("Get JSON value from the cache.")
 
 		Payload(CacheGetRequest)
-		Result(Bytes)
+		Result(Any)
 
 		HTTP(func() {
 			GET("/v1/cache")
diff --git a/internal/clients/redis/client.go b/internal/clients/redis/client.go
index 0b1f1c9..fbe9f52 100644
--- a/internal/clients/redis/client.go
+++ b/internal/clients/redis/client.go
@@ -31,7 +31,7 @@ func New(addr, user, pass string, db int, defaultTTL time.Duration) *Client {
 	}
 }
 
-func (c *Client) Get(ctx context.Context, key string) ([]byte, error) {
+func (c *Client) Get(ctx context.Context, key string) (interface{}, error) {
 	result := c.rdb.Get(ctx, key)
 	if result.Err() != nil {
 		if result.Err() == redis.Nil {
@@ -39,7 +39,7 @@ func (c *Client) Get(ctx context.Context, key string) ([]byte, error) {
 		}
 		return nil, result.Err()
 	}
-	return []byte(result.Val()), nil
+	return result.Val(), nil
 }
 
 func (c *Client) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error {
diff --git a/internal/service/cache/service.go b/internal/service/cache/service.go
index ee824a4..7c4357f 100644
--- a/internal/service/cache/service.go
+++ b/internal/service/cache/service.go
@@ -13,7 +13,7 @@ import (
 )
 
 type Cache interface {
-	Get(ctx context.Context, key string) ([]byte, error)
+	Get(ctx context.Context, key string) (interface{}, error)
 	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
 }
 
@@ -29,7 +29,7 @@ func New(cache Cache, logger *zap.Logger) *Service {
 	}
 }
 
-func (s *Service) Get(ctx context.Context, req *cache.CacheGetRequest) ([]byte, error) {
+func (s *Service) Get(ctx context.Context, req *cache.CacheGetRequest) (interface{}, error) {
 	var operation = zap.String("operation", "get")
 	if req.Key == "" || req.Namespace == "" || req.Scope == "" {
 		s.logger.Error("bad request: missing key or namespace or scopes", operation)
-- 
GitLab