From 3c12fef571b067957b418940cbf596a93ae9271f Mon Sep 17 00:00:00 2001 From: Syd Xu Date: Tue, 24 Dec 2024 17:38:01 +0800 Subject: [PATCH] fix(enum): HideIfExists unmarshal --- marketing-api/enum/hide_if_exists.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/marketing-api/enum/hide_if_exists.go b/marketing-api/enum/hide_if_exists.go index 81c7ef0..08f442b 100644 --- a/marketing-api/enum/hide_if_exists.go +++ b/marketing-api/enum/hide_if_exists.go @@ -12,7 +12,7 @@ const ( // HideIfExists_FILTER 过滤,仅安卓应用推广时支持,其他情况传入不生效 HideIfExists_FILTER HideIfExists = "FILTER" // HideIfExists_TARGETING 定向 - HideIfExists_TARGETING HideIfExists = "TARGET" + HideIfExists_TARGETING HideIfExists = "TARGETING" ) // UnmarshalJSON implement json Unmarshal interface @@ -20,19 +20,19 @@ func (he *HideIfExists) UnmarshalJSON(b []byte) (err error) { if b[0] == '"' && b[len(b)-1] == '"' { b = b[1 : len(b)-1] } - var ret int str := string(b) - switch str { - case "UNLIMITED": - ret = 0 - case "FILTER": - ret = 1 - case "TARGETING": - ret = 2 - default: - ret, _ = strconv.Atoi(str) + if ret, err := strconv.Atoi(str); err == nil { + switch ret { + case 0: + *he = HideIfExists_UNLIMITED + case 1: + *he = HideIfExists_FILTER + case 2: + *he = HideIfExists_TARGETING + } + } else { + *he = HideIfExists(str) } - *he = HideIfExists(ret) return }