made asc sorting optional and added regression tests
This commit is contained in:
parent
a1a335a53c
commit
dc8463a290
4 changed files with 36 additions and 17 deletions
26
filter.go
26
filter.go
|
|
@ -115,27 +115,23 @@ func NewQuery(s string) (q *Query, err error) {
|
|||
}
|
||||
if !q.s.enabled {
|
||||
s := strings.SplitN(v, ":", 3)
|
||||
if len(s) == 3 {
|
||||
if s[0] == "sort" {
|
||||
if s[0] == "sort" && len(s) >= 2 {
|
||||
q.s.fields = strings.Split(s[1], ".")
|
||||
if err = checkFields(q.s.fields, v); err != nil {
|
||||
return
|
||||
}
|
||||
if len(s) == 3 {
|
||||
switch s[2] {
|
||||
case asc, desc:
|
||||
q.s.fields = strings.Split(s[1], ".")
|
||||
if err = checkFields(q.s.fields, v); err != nil {
|
||||
return
|
||||
}
|
||||
if len(q.s.fields) > 0 {
|
||||
if s[2] == desc {
|
||||
q.s.desc = true
|
||||
}
|
||||
q.s.enabled = true
|
||||
}
|
||||
continue
|
||||
case desc:
|
||||
q.s.desc = true
|
||||
case asc:
|
||||
default:
|
||||
err = newErr("invalid sort: " + v)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
q.s.enabled = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
m := strings.SplitN(v, ":", 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue