Make names case insensitive for API
This commit is contained in:
@@ -2,6 +2,7 @@ package operator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@@ -15,6 +16,36 @@ func (re Regex) MarshalBSON() ([]byte, error) {
|
||||
return filterMarshal("$regex", re.Key, re.Value)
|
||||
}
|
||||
|
||||
type CaseInsensitives struct {
|
||||
Key string
|
||||
Values []string
|
||||
}
|
||||
|
||||
func (cis CaseInsensitives) MarshalBSON() ([]byte, error) {
|
||||
values := cis.Values
|
||||
if len(cis.Values) == 0 {
|
||||
values = []string{".*"}
|
||||
}
|
||||
ci := CaseInsensitive{
|
||||
Key: cis.Key,
|
||||
Value: fmt.Sprintf("^(%s)$", strings.Join(values, "|")),
|
||||
}
|
||||
return bson.Marshal(ci)
|
||||
}
|
||||
|
||||
type CaseInsensitive struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
func (ci CaseInsensitive) MarshalBSON() ([]byte, error) {
|
||||
value := ci.Value
|
||||
if value == "" {
|
||||
value = "^$"
|
||||
}
|
||||
return bson.Marshal(Regex{Key: ci.Key, Value: "(?i)" + ci.Value})
|
||||
}
|
||||
|
||||
type FilterIn struct {
|
||||
Key string
|
||||
Values []interface{}
|
||||
|
||||
Reference in New Issue
Block a user