Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
31
pkg/clickhouse/options.go
Normal file
31
pkg/clickhouse/options.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package clickhouse
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fiskerinc.com/modules/validator"
|
||||
|
||||
"github.com/gorilla/schema"
|
||||
)
|
||||
|
||||
const PageQueryOptionsLimitMaximum = 100
|
||||
|
||||
type PageQueryOptions struct {
|
||||
Limit int `json:"limit" validate:"gte=0,lte=100"`
|
||||
Offset int `json:"offset" validate:"gte=0"`
|
||||
}
|
||||
|
||||
// ParsePageQuery parses PageQueryOptions from http request
|
||||
func ParsePageQuery(r *http.Request) (PageQueryOptions, error) {
|
||||
decoder := schema.NewDecoder()
|
||||
options := PageQueryOptions{}
|
||||
|
||||
decoder.SetAliasTag("json")
|
||||
decoder.Decode(&options, r.URL.Query())
|
||||
err := validator.ValidateStruct(options)
|
||||
if err == nil && options.Limit == 0 {
|
||||
options.Limit = PageQueryOptionsLimitMaximum
|
||||
}
|
||||
|
||||
return options, err
|
||||
}
|
||||
Reference in New Issue
Block a user