nidus-sync/resource/query_params.go

31 lines
534 B
Go
Raw Normal View History

2026-04-01 18:12:46 +00:00
package resource
2026-03-10 15:46:17 +00:00
2026-04-01 18:12:46 +00:00
import (
//"github.com/gorilla/schema"
)
type QueryParams struct {
2026-03-10 15:46:17 +00:00
Limit *int `schema:"limit"`
Query *string `schema:"query"`
2026-03-10 15:46:17 +00:00
Sort *string `schema:"sort"`
Type *string `schema:"type"`
}
2026-04-01 18:12:46 +00:00
func (qp QueryParams) SortOrDefault(default_name string, ascending bool) (string, bool) {
2026-03-10 15:46:17 +00:00
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
}