From 819e5f56c5ddf7315be58a3b20f41c7f0280b97c Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 3 Feb 2020 11:08:01 +0800 Subject: [PATCH] fixed https://github.com/crawlab-team/crawlab/issues/202 --- backend/utils/model.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/utils/model.go b/backend/utils/model.go index 21a295d6..048b0001 100644 --- a/backend/utils/model.go +++ b/backend/utils/model.go @@ -2,9 +2,9 @@ package utils import ( "crawlab/constants" + "encoding/json" "github.com/globalsign/mgo/bson" - "strconv" - "time" + "strings" ) func IsObjectIdNull(id bson.ObjectId) bool { @@ -12,16 +12,13 @@ func IsObjectIdNull(id bson.ObjectId) bool { } func InterfaceToString(value interface{}) string { - switch realValue := value.(type) { - case bson.ObjectId: - return realValue.Hex() - case string: - return realValue - case int: - return strconv.Itoa(realValue) - case time.Time: - return realValue.String() - default: + bytes, err := json.Marshal(value) + if err != nil { return "" } + str := string(bytes) + if strings.HasPrefix(str, "\"") && strings.HasSuffix(str, "\"") { + str = str[1 : len(str)-1] + } + return str }