Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
30
pkg/mongo/sort.go
Normal file
30
pkg/mongo/sort.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func AdaptOrder(orderString string, adaptMap map[string]string) string {
|
||||
for old, new := range adaptMap {
|
||||
orderString = strings.Replace(orderString, old, new, -1)
|
||||
}
|
||||
|
||||
return orderString
|
||||
}
|
||||
|
||||
func getOrder(queryOrder string) bson.M {
|
||||
order := bson.M{"_id": -1}
|
||||
orderSlice := strings.Split(queryOrder, " ")
|
||||
if len(orderSlice) > 1 {
|
||||
asc := 1
|
||||
if strings.ToLower(orderSlice[1]) == "desc" {
|
||||
asc = -1
|
||||
}
|
||||
|
||||
order = bson.M{orderSlice[0]: asc}
|
||||
}
|
||||
|
||||
return order
|
||||
}
|
||||
Reference in New Issue
Block a user