chore: custom error
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package restutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func IntParam(r *http.Request, key string) (val int, err error) {
|
||||
str := r.URL.Query().Get(key)
|
||||
if str == "" {
|
||||
return
|
||||
}
|
||||
|
||||
val, err = strconv.Atoi(str)
|
||||
if err != nil {
|
||||
err = WrappErr(
|
||||
err,
|
||||
ErrorTypeValidation,
|
||||
fmt.Sprintf("failed to parse query parameter '%s': not an int", key),
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user