Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Created October 19, 2016 19:37
Show Gist options
  • Save thrawn01/299abf17ae62ed9fd19617bdab32820f to your computer and use it in GitHub Desktop.
Save thrawn01/299abf17ae62ed9fd19617bdab32820f to your computer and use it in GitHub Desktop.
func (c *TagsAPIController) List(w http.ResponseWriter, r *http.Request, params map[string]string) (interface{}, error) {
val := NewValidator()
val.Param("limit").IsInt().Default("1000").Max(1000).Min(0)
val.Param("resolution").Allowed([]string{"month", "day", "year"})
val.Param("page").Allowed([]string{"first", "last", "next", "prev"}).Default("first")
val.Param("prefix")
val.Param("tag")
params, err := val.Validate(r)
if err != nil {
return nil, err
}
limit := params.Int("limit")
if params.Set("prefix") {
// Do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment