mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
gate.io: Enforce the use of 'convert.StringToFloat64' and permit its use in outbound requests (#1308)
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -222,6 +222,15 @@ func (f *StringToFloat64) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface.
|
||||
func (f StringToFloat64) MarshalJSON() ([]byte, error) {
|
||||
if f == 0 {
|
||||
return []byte(jsonStringIdent + jsonStringIdent), nil
|
||||
}
|
||||
val := strconv.FormatFloat(float64(f), 'f', -1, 64)
|
||||
return []byte(jsonStringIdent + val + jsonStringIdent), nil
|
||||
}
|
||||
|
||||
// Float64 returns the float64 value of the FloatString.
|
||||
func (f *StringToFloat64) Float64() float64 {
|
||||
return float64(*f)
|
||||
|
||||
@@ -353,6 +353,24 @@ func TestStringToFloat64(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("error cannot be nil")
|
||||
}
|
||||
|
||||
data, err := json.Marshal(StringToFloat64(0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if string(data) != `""` {
|
||||
t.Fatalf("expected empty string, got %v", string(data))
|
||||
}
|
||||
|
||||
data, err = json.Marshal(StringToFloat64(1337.1337))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if string(data) != `"1337.1337"` {
|
||||
t.Fatalf("expected \"1337.1337\" string, got %v", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringToFloat64Decimal(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user