本文整理匯總了Golang中github.com/rs/rest-layer/resource.Resource.Validator方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resource.Validator方法的具體用法?Golang Resource.Validator怎麽用?Golang Resource.Validator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rs/rest-layer/resource.Resource
的用法示例。
在下文中一共展示了Resource.Validator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: listParamResolver
func listParamResolver(r *resource.Resource, p graphql.ResolveParams, params url.Values) (lookup *resource.Lookup, page int, perPage int, err error) {
page = 1
// Default value on non HEAD request for perPage is -1 (pagination disabled)
perPage = -1
if l := r.Conf().PaginationDefaultLimit; l > 0 {
perPage = l
}
if p, ok := p.Args["page"].(string); ok && p != "" {
i, err := strconv.ParseUint(p, 10, 32)
if err != nil {
return nil, 0, 0, errors.New("invalid `limit` parameter")
}
page = int(i)
}
if l, ok := p.Args["limit"].(string); ok && l != "" {
i, err := strconv.ParseUint(l, 10, 32)
if err != nil {
return nil, 0, 0, errors.New("invalid `limit` parameter")
}
perPage = int(i)
}
if perPage == -1 && page != 1 {
return nil, 0, 0, errors.New("cannot use `page' parameter with no `limit' paramter on a resource with no default pagination size")
}
lookup = resource.NewLookup()
if sort, ok := p.Args["sort"].(string); ok && sort != "" {
if err := lookup.SetSort(sort, r.Validator()); err != nil {
return nil, 0, 0, fmt.Errorf("invalid `sort` parameter: %v", err)
}
}
if filter, ok := p.Args["filter"].(string); ok && filter != "" {
if err := lookup.AddFilter(filter, r.Validator()); err != nil {
return nil, 0, 0, fmt.Errorf("invalid `filter` parameter: %v", err)
}
}
if params != nil {
if filter := params.Get("filter"); filter != "" {
if err := lookup.AddFilter(filter, r.Validator()); err != nil {
return nil, 0, 0, fmt.Errorf("invalid `filter` parameter: %v", err)
}
}
}
return
}