Complete rewrite of the library.

This commit is contained in:
2023-12-12 21:30:26 +00:00
parent 3217edf37f
commit 4fc826c1f6
27 changed files with 1153 additions and 1372 deletions
+43
View File
@@ -0,0 +1,43 @@
package gql
import (
"fmt"
"github.com/gookit/goutil/strutil"
)
func searchForKeysInMapStringInterface(msi map[string]interface{}, key string) (value any) {
if msi == nil {
return nil
}
return msi[key]
}
func calculateHash(query *Query) string {
return strutil.Md5(query.JsonQuery)
}
func (b *BaseClient) cacheLookup(hash string) []byte {
obj, _ := b.cache.Get(hash)
return obj
}
func (b *BaseClient) decodeResponse(response []byte) (any, error) {
switch b.responseType {
case "mapstring":
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()})
return nil, err
}
return result, nil
case "string":
return string(response), nil
case "byte":
return response, nil
default:
b.Logger.Error("Can't decode response;", map[string]interface{}{"error": "unknown response type"})
return nil, fmt.Errorf("Can't decode response - unknown response type specified")
}
}