-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package model | ||
|
||
import "strconv" | ||
|
||
// Uint64 support string quoted number in json | ||
type Uint64 uint64 | ||
|
||
// UnmarshalJSON implement json Unmarshal interface | ||
func (u64 *Uint64) UnmarshalJSON(b []byte) (err error) { | ||
if b[0] == '"' && b[len(b)-1] == '"' { | ||
b = b[1 : len(b)-1] | ||
} | ||
i, _ := strconv.ParseUint(string(b), 10, 64) | ||
*u64 = Uint64(i) | ||
return | ||
} | ||
|
||
func (u64 Uint64) Value() uint64 { | ||
return uint64(u64) | ||
} | ||
|
||
func (u64 Uint64) String() string { | ||
return strconv.FormatUint(uint64(u64), 10) | ||
} | ||
|
||
// Int64 support string quoted number in json | ||
type Int64 int64 | ||
|
||
// UnmarshalJSON implement json Unmarshal interface | ||
func (i64 *Int64) UnmarshalJSON(b []byte) (err error) { | ||
if b[0] == '"' && b[len(b)-1] == '"' { | ||
b = b[1 : len(b)-1] | ||
} | ||
i, _ := strconv.ParseInt(string(b), 10, 64) | ||
*i64 = Int64(i) | ||
return | ||
} | ||
|
||
func (i64 Int64) Value() int64 { | ||
return int64(i64) | ||
} | ||
|
||
func (i64 Int64) String() string { | ||
return strconv.FormatInt(int64(i64), 10) | ||
} | ||
|
||
// Float64 support string quoted number in json | ||
type Float64 float64 | ||
|
||
// UnmarshalJSON implement json Unmarshal interface | ||
func (f64 *Float64) UnmarshalJSON(b []byte) (err error) { | ||
if b[0] == '"' && b[len(b)-1] == '"' { | ||
b = b[1 : len(b)-1] | ||
} | ||
i, _ := strconv.ParseFloat(string(b), 64) | ||
*f64 = Float64(i) | ||
return | ||
} | ||
|
||
func (f64 Float64) Value() float64 { | ||
return float64(f64) | ||
} | ||
|
||
func (f64 Float64) String(prec int) string { | ||
return strconv.FormatFloat(float64(64), 'f', prec, 64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters