mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
ToJson fix error handling (#16)
This commit is contained in:
1 parent
3905c0bde1
commit
a8996933bf
1 file changed
+2
-2
@@ -79,10 +79,10 @@ func ToString(value interface{}) string {
|
|||||||
func ToJson(value interface{}) (string, error) {
|
func ToJson(value interface{}) (string, error) {
|
||||||
res, err := json.Marshal(value)
|
res, err := json.Marshal(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res = []byte("")
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(res), err
|
return string(res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToFloat convert value to a float64, if input is not a float return 0.0 and error
|
// ToFloat convert value to a float64, if input is not a float return 0.0 and error
|
||||||
|
|||||||
Reference in new issue
Block a user