mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* tag optional sonic and allow full library conversion * Add workflow and disallow arm and darwin usage * Add basic hotswap benchmark * linter: fix * use bash * linter: fix? * Fix whoopsie, add to make file, also add mention in features list. * test enforcement * actually read documentation see if this works * linter: fix * linter: fix * sonic: bump tagged version * encoding/json: drop build tag arch and os filters * encoding/json: consolidate tests * encoding/json: log build tag usage * rm superfluous builds * glorious/nits: add template change and regen docs * glorious/nits: update commentary on nolint directive * glorious/nits: rm init func and log results in main.go * Test to actually pull flag in * linter: fix * thrasher: nits * gk: nits 4 goflags goooooooooo! * gk: nits rn * make sonic default json implementation * screen 386 * linter: fix * Add commentary * glorious: nits Makefile not working * gk: nits * gk: nits whoops * whoopsirino * mention 32bit systems won't be sonic * gk: super-duper nit of extremes --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
package mock
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"net/url"
|
|
"reflect"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
|
)
|
|
|
|
// MatchURLVals matches url.Value query strings
|
|
func MatchURLVals(v1, v2 url.Values) bool {
|
|
if len(v1) != len(v2) {
|
|
return false
|
|
}
|
|
|
|
if len(v1) == 0 && len(v2) == 0 {
|
|
return true
|
|
}
|
|
|
|
for key, val := range v1 {
|
|
if key == "nonce" || key == "signature" || key == "timestamp" || key == "tonce" || key == "key" { // delta values
|
|
if _, ok := v2[key]; !ok {
|
|
return false
|
|
}
|
|
continue
|
|
}
|
|
|
|
if val2, ok := v2[key]; ok {
|
|
if strings.Join(val2, "") == strings.Join(val, "") {
|
|
continue
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// DeriveURLValsFromJSONMap gets url vals from a map[string]string encoded JSON body
|
|
func DeriveURLValsFromJSONMap(payload []byte) (url.Values, error) {
|
|
var vals = url.Values{}
|
|
if len(payload) == 0 {
|
|
return vals, nil
|
|
}
|
|
intermediary := make(map[string]interface{})
|
|
err := json.Unmarshal(payload, &intermediary)
|
|
if err != nil {
|
|
return vals, err
|
|
}
|
|
|
|
for k, v := range intermediary {
|
|
switch val := v.(type) {
|
|
case string:
|
|
vals.Add(k, val)
|
|
case bool:
|
|
vals.Add(k, strconv.FormatBool(val))
|
|
case float64:
|
|
vals.Add(k, strconv.FormatFloat(val, 'f', -1, 64))
|
|
case map[string]interface{}, []interface{}, nil:
|
|
vals.Add(k, fmt.Sprintf("%v", val))
|
|
default:
|
|
log.Println(reflect.TypeOf(val))
|
|
return vals, errors.New("unhandled conversion type, please add as needed")
|
|
}
|
|
}
|
|
|
|
return vals, nil
|
|
}
|