-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo.go
More file actions
40 lines (37 loc) · 723 Bytes
/
mongo.go
File metadata and controls
40 lines (37 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package lib
import (
"github.com/spf13/cast"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func MustMongoSlice2StringSlice(i interface{}) []string {
pa, ok := i.(primitive.A)
if ok {
res := []string{}
for _, v := range pa {
res = append(res, cast.ToString(v))
}
return res
} else {
res, err := cast.ToStringSliceE(i)
if err != nil {
return []string{}
}
return res
}
}
func MongoSlice2StringSlice(i interface{}) ([]string, error) {
pa, ok := i.(primitive.A)
if ok {
res := []string{}
for _, v := range pa {
res = append(res, cast.ToString(v))
}
return res, nil
} else {
res, err := cast.ToStringSliceE(i)
if err != nil {
return []string{}, err
}
return res, nil
}
}