mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 15:09:51 +00:00
* Bump CI versions * Specifically set go version as 1.17.x bumps it to 1.18 * Another * Adjust AppVeyor * Part 1 of linter issues * Part 2 * Fix various linters and improvements * Part 3 * Finishing touches * Tests and EqualFold * Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests * Fix nitterinos and bump golangci-lint timeout for AppVeyor * Address nits, ensure all books are returned on err due to syncer regression * Fix the wiggins * Fix duplication * Fix nitterinos
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package mock
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"net/url"
|
|
"reflect"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// 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
|
|
}
|