package util import ( "errors" "strconv" "github.com/julienschmidt/httprouter" ) func ParseNumberFromParams(name string, p httprouter.Params, unsigned bool) (int, error) { snum := p.ByName(name) num, err := strconv.Atoi(snum) if err != nil { return 0, err } if unsigned && num < 0 { return 0, errors.New("number is negative") } return num, err } func ParseIDFromParams(p httprouter.Params) (int, error) { return ParseNumberFromParams("id", p, true) }