forked from go-bongo/bongo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.go
More file actions
34 lines (27 loc) · 671 Bytes
/
validate.go
File metadata and controls
34 lines (27 loc) · 671 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
package bongo
import (
"github.com/globalsign/mgo/bson"
"reflect"
)
func ValidateRequired(val interface{}) bool {
valueOf := reflect.ValueOf(val)
return valueOf.Interface() != reflect.Zero(valueOf.Type()).Interface()
}
func ValidateMongoIdRef(id bson.ObjectId, collection *Collection) bool {
count, err := collection.Collection().Find(bson.M{"_id": id}).Count()
if err != nil || count <= 0 {
return false
}
return true
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func ValidateInclusionIn(value string, options []string) bool {
return stringInSlice(value, options)
}