This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
api/utils/sanitize_sort.go

18 lines
360 B
Go
Raw Normal View History

2020-06-04 13:06:32 +00:00
package utils
import "strings"
func SanitizeSort(sort string) string {
trimmed := strings.TrimSpace(sort)
splitted := strings.Split(trimmed, " ")
length := len(splitted)
2020-06-04 15:45:56 +00:00
if length != 2 {
2020-06-04 13:06:32 +00:00
return ""
}
keyword := "ASC"
if strings.ToUpper(splitted[1]) == "DESC" {
2020-06-04 13:06:32 +00:00
keyword = "DESC"
}
return strings.ToLower(Underscore(splitted[0])) + " " + keyword
}