Skip to content
Snippets Groups Projects
Commit 0244a381 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

#3 change GET endpoint response type to json

parent 9c3207f6
No related branches found
No related tags found
1 merge request!3Create SET cache endpoint
Pipeline #49805 passed with stage
in 43 seconds
......@@ -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")
......
......@@ -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 {
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment