From 30271de70a0b618e21446edf397d8b6f2d251daf Mon Sep 17 00:00:00 2001 From: shenzhuan Date: Fri, 4 Nov 2022 16:23:45 +0800 Subject: [PATCH] stringToInt32List --- utils.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils.go b/utils.go index d5a923f..e883a97 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package common import ( "math" "strconv" + "strings" ) /* @@ -63,3 +64,21 @@ func ConverToBinary(n int) string { } return res } + +// 格式化页面传入的cartIds +func SplitToInt32List(str string, sep string) (int32List []int32) { + tempStr := strings.Split(str, sep) + if len(tempStr) > 0 { + for _, item := range tempStr { + if item == "" { + continue + } + val, err := strconv.ParseInt(item, 10, 32) + if err != nil { + continue + } + int32List = append(int32List, int32(val)) + } + } + return int32List +}