From 5d14b794dd0aa32dc19f64ab71628db1f1776a09 Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Mon, 5 Dec 2022 15:16:42 +0700 Subject: [PATCH] add func get value by key with binding --- get_by_key.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/get_by_key.go b/get_by_key.go index b4cda39..1e30cff 100644 --- a/get_by_key.go +++ b/get_by_key.go @@ -3,6 +3,7 @@ package redisdb import ( "context" "encoding/json" + "errors" ) // GetValueByKey ... @@ -15,14 +16,11 @@ func (s Server) GetValueByKey(ctx context.Context, key string) string { return value } -// GetJSON ... -func (s Server) GetJSON(ctx context.Context, key string, result interface{}) (ok bool) { +// GetValueByKeyWithBinding ... +func (s Server) GetValueByKeyWithBinding(ctx context.Context, key string, result interface{}) error { v := s.GetValueByKey(ctx, key) if v == "" { - return false + return errors.New("key not found") } - if err := json.Unmarshal([]byte(v), result); err != nil { - return false - } - return true + return json.Unmarshal([]byte(v), result) }