Move QueryParams to resource module
This commit is contained in:
parent
ab519020fc
commit
a656d45a6d
16 changed files with 641 additions and 583 deletions
30
resource/query_params.go
Normal file
30
resource/query_params.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package resource
|
||||
|
||||
import (
|
||||
//"github.com/gorilla/schema"
|
||||
)
|
||||
|
||||
type QueryParams struct {
|
||||
Limit *int `schema:"limit"`
|
||||
Query *string `schema:"query"`
|
||||
Sort *string `schema:"sort"`
|
||||
Type *string `schema:"type"`
|
||||
}
|
||||
|
||||
func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string, bool) {
|
||||
if qp.Sort == nil {
|
||||
return default_name, ascending
|
||||
}
|
||||
s := *qp.Sort
|
||||
if s == "" {
|
||||
return default_name, ascending
|
||||
}
|
||||
a := true
|
||||
if s[0] == '-' {
|
||||
a = false
|
||||
}
|
||||
if s[0] == '+' || s[0] == '-' {
|
||||
s = s[1:]
|
||||
}
|
||||
return s, a
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue