general improvements (#2)

* Replaced strutil.Md5 with crypto/md5 and encoding/hex to reduce dependency and potential allocations.

* Move to improved logging library.

* fixup! Move to improved logging library.
This commit is contained in:
2024-06-28 09:22:52 +01:00
committed by GitHub
parent 42170f9b8e
commit 36ef16ad3d
13 changed files with 755 additions and 185 deletions
+13 -4
View File
@@ -1,10 +1,12 @@
package gql
import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/goccy/go-json"
"github.com/gookit/goutil/strutil"
libpack_logger "github.com/lukaszraczylo/go-simple-graphql/logging"
)
func searchForKeysInMapStringInterface(msi map[string]interface{}, key string) (value any) {
@@ -15,7 +17,8 @@ func searchForKeysInMapStringInterface(msi map[string]interface{}, key string) (
}
func calculateHash(query *Query) string {
return strutil.Md5(query.JsonQuery)
hash := md5.Sum([]byte(query.JsonQuery))
return hex.EncodeToString(hash[:])
}
func (b *BaseClient) cacheLookup(hash string) []byte {
@@ -29,7 +32,10 @@ func (b *BaseClient) decodeResponse(response []byte) (any, error) {
var result map[string]interface{}
err := json.Unmarshal(response, &result)
if err != nil {
b.Logger.Error("Can't decode response into mapstring", map[string]interface{}{"error": err.Error()})
b.Logger.Error(&libpack_logger.LogMessage{
Message: "Can't decode response into mapstring",
Pairs: map[string]interface{}{"error": err.Error()},
})
return nil, err
}
return result, nil
@@ -38,7 +44,10 @@ func (b *BaseClient) decodeResponse(response []byte) (any, error) {
case "byte":
return response, nil
default:
b.Logger.Error("Can't decode response;", map[string]interface{}{"error": "unknown response type"})
b.Logger.Error(&libpack_logger.LogMessage{
Message: "Can't decode response",
Pairs: map[string]interface{}{"error": "unknown response type"},
})
return nil, fmt.Errorf("Can't decode response - unknown response type specified")
}
}