1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 05:25:58 +00:00

Update to version 10.5.0 | Read HISTORY.md for more

Former-commit-id: 41b1947aafa258d342bbf9d22baeecc946d198a4
This commit is contained in:
Gerasimos Maropoulos
2018-03-24 10:39:44 +02:00
parent 2955edd81c
commit 66d367b255
15 changed files with 434 additions and 248 deletions

View File

@@ -179,7 +179,7 @@ func (r RequestParams) GetIntUnslashed(key string) (int, error) {
}
return -1, memstore.ErrIntParse.Format(v)
return -1, fmt.Errorf("unable to find int for '%s'", key)
}
// Len returns the full length of the parameters.
@@ -456,39 +456,35 @@ type Context interface {
// URLParam returns true if the url parameter exists, otherwise false.
URLParamExists(name string) bool
// URLParamDefault returns the get parameter from a request, if not found then "def" is returned.
// URLParamDefault returns the get parameter from a request,
// if not found then "def" is returned.
URLParamDefault(name string, def string) string
// URLParam returns the get parameter from a request , if any.
// URLParam returns the get parameter from a request, if any.
URLParam(name string) string
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request,
// returns an error if parse failed.
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request.
URLParamTrim(name string) string
// URLParamTrim returns the escaped url query parameter from a request,
// returns an error if parse failed.
// URLParamTrim returns the escaped url query parameter from a request.
URLParamEscape(name string) string
// URLParamIntDefault returns the url query parameter as int value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
URLParamIntDefault(name string, def int) (int, error)
// URLParamInt returns the url query parameter as int value from a request,
// returns an error if parse failed.
// returns -1 and an error if parse failed.
URLParamInt(name string) (int, error)
// URLParamInt64Default returns the url query parameter as int64 value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
URLParamInt64Default(name string, def int64) (int64, error)
// URLParamIntDefault returns the url query parameter as int value from a request,
// if not found or parse failed then "def" is returned.
URLParamIntDefault(name string, def int) int
// URLParamInt64 returns the url query parameter as int64 value from a request,
// returns an error if parse failed.
// returns -1 and an error if parse failed.
URLParamInt64(name string) (int64, error)
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
URLParamFloat64Default(name string, def float64) (float64, error)
// URLParamInt64Default returns the url query parameter as int64 value from a request,
// if not found or parse failed then "def" is returned.
URLParamInt64Default(name string, def int64) int64
// URLParamFloat64 returns the url query parameter as float64 value from a request,
// returns an error if parse failed.
// returns -1 and an error if parse failed.
URLParamFloat64(name string) (float64, error)
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
// if not found or parse failed then "def" is returned.
URLParamFloat64Default(name string, def float64) float64
// URLParamBool returns the url query parameter as boolean value from a request,
// returns an error if parse failed.
// returns an error if parse failed or not found.
URLParamBool(name string) (bool, error)
// URLParams returns a map of GET query parameters separated by comma if more than one
// it returns an empty map if nothing found.
@@ -522,36 +518,36 @@ type Context interface {
// PostValueTrim returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", without trailing spaces.
PostValueTrim(name string) string
// PostValueIntDefault returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found returns the "def".
PostValueIntDefault(name string, def int) (int, error)
// PostValueInt returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found returns 0.
// If not found returns -1 and a non-nil error.
PostValueInt(name string) (int, error)
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int64.
// PostValueIntDefault returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found returns the "def".
PostValueInt64Default(name string, def int64) (int64, error)
// If not found returns or parse errors the "def".
PostValueIntDefault(name string, def int) int
// PostValueInt64 returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns 0.0.
// If not found returns -1 and a no-nil error.
PostValueInt64(name string) (int64, error)
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int64.
//
// If not found or parse errors returns the "def".
PostValueInt64Default(name string, def int64) int64
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns the "def".
PostValueFloat64Default(name string, def float64) (float64, error)
/// PostValueInt64Default returns the parsed form data from POST, PATCH,
// If not found returns -1 and a non-nil error.
PostValueFloat64(name string) (float64, error)
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns 0.0.
PostValueFloat64(name string) (float64, error)
// If not found or parse errors returns the "def".
PostValueFloat64Default(name string, def float64) float64
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as bool.
//
@@ -1641,79 +1637,103 @@ func (ctx *context) URLParamExists(name string) bool {
// URLParamDefault returns the get parameter from a request, if not found then "def" is returned.
func (ctx *context) URLParamDefault(name string, def string) string {
v := ctx.request.URL.Query().Get(name)
if v == "" {
return def
if v := ctx.request.URL.Query().Get(name); v != "" {
return v
}
return v
return def
}
// URLParam returns the get parameter from a request , if any.
// URLParam returns the get parameter from a request, if any.
func (ctx *context) URLParam(name string) string {
return ctx.URLParamDefault(name, "")
}
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request,
// returns an error if parse failed.
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request.
func (ctx *context) URLParamTrim(name string) string {
return strings.TrimSpace(ctx.URLParam(name))
}
// URLParamTrim returns the escaped url query parameter from a request,
// returns an error if parse failed.
// URLParamTrim returns the escaped url query parameter from a request.
func (ctx *context) URLParamEscape(name string) string {
return DecodeQuery(ctx.URLParam(name))
}
// URLParamIntDefault returns the url query parameter as int value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
func (ctx *context) URLParamIntDefault(name string, def int) (int, error) {
v := ctx.URLParam(name)
if v == "" {
return def, nil
}
return strconv.Atoi(v)
}
var errURLParamNotFound = errors.New("url param '%s' does not exist")
// URLParamInt returns the url query parameter as int value from a request,
// returns an error if parse failed.
// returns -1 and an error if parse failed or not found.
func (ctx *context) URLParamInt(name string) (int, error) {
return ctx.URLParamIntDefault(name, 0)
if v := ctx.URLParam(name); v != "" {
n, err := strconv.Atoi(v)
if err != nil {
return -1, err
}
return n, nil
}
return -1, errURLParamNotFound.Format(name)
}
// URLParamInt64Default returns the url query parameter as int64 value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
func (ctx *context) URLParamInt64Default(name string, def int64) (int64, error) {
v := ctx.URLParam(name)
if v == "" {
return def, nil
// URLParamIntDefault returns the url query parameter as int value from a request,
// if not found or parse failed then "def" is returned.
func (ctx *context) URLParamIntDefault(name string, def int) int {
v, err := ctx.URLParamInt(name)
if err != nil {
return def
}
return strconv.ParseInt(v, 10, 64)
return v
}
// URLParamInt64 returns the url query parameter as int64 value from a request,
// returns an error if parse failed.
// returns -1 and an error if parse failed or not found.
func (ctx *context) URLParamInt64(name string) (int64, error) {
return ctx.URLParamInt64Default(name, 0.0)
if v := ctx.URLParam(name); v != "" {
n, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return -1, err
}
return n, nil
}
return -1, errURLParamNotFound.Format(name)
}
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
// if not found then "def" is returned.
// Returns an error if parse failed.
func (ctx *context) URLParamFloat64Default(name string, def float64) (float64, error) {
v := ctx.URLParam(name)
if v == "" {
return def, nil
// URLParamInt64Default returns the url query parameter as int64 value from a request,
// if not found or parse failed then "def" is returned.
func (ctx *context) URLParamInt64Default(name string, def int64) int64 {
v, err := ctx.URLParamInt64(name)
if err != nil {
return def
}
return strconv.ParseFloat(v, 64)
return v
}
// URLParamFloat64 returns the url query parameter as float64 value from a request,
// returns an error if parse failed.
// returns an error and -1 if parse failed.
func (ctx *context) URLParamFloat64(name string) (float64, error) {
return ctx.URLParamFloat64Default(name, 0.0)
if v := ctx.URLParam(name); v != "" {
n, err := strconv.ParseFloat(v, 64)
if err != nil {
return -1, err
}
return n, nil
}
return -1, errURLParamNotFound.Format(name)
}
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
// if not found or parse failed then "def" is returned.
func (ctx *context) URLParamFloat64Default(name string, def float64) float64 {
v, err := ctx.URLParamFloat64(name)
if err != nil {
return def
}
return v
}
// URLParamBool returns the url query parameter as boolean value from a request,
@@ -1836,54 +1856,64 @@ func (ctx *context) PostValueTrim(name string) string {
return strings.TrimSpace(ctx.PostValue(name))
}
// PostValueIntDefault returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found returns the "def".
func (ctx *context) PostValueIntDefault(name string, def int) (int, error) {
v := ctx.PostValue(name)
if v == "" {
return def, nil
}
return strconv.Atoi(v)
}
var errUnableToFindPostValue = errors.New("unable to find post value '%s'")
// PostValueInt returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found returns 0.
// If not found returns -1 and a non-nil error.
func (ctx *context) PostValueInt(name string) (int, error) {
return ctx.PostValueIntDefault(name, 0)
}
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int64.
//
// If not found returns the "def".
func (ctx *context) PostValueInt64Default(name string, def int64) (int64, error) {
v := ctx.PostValue(name)
if v == "" {
return def, nil
return -1, errUnableToFindPostValue.Format(name)
}
return strconv.ParseInt(v, 10, 64)
return strconv.Atoi(v)
}
// PostValueIntDefault returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int.
//
// If not found or parse errors returns the "def".
func (ctx *context) PostValueIntDefault(name string, def int) int {
if v, err := ctx.PostValueInt(name); err == nil {
return v
}
return def
}
// PostValueInt64 returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns 0.0.
// If not found returns -1 and a non-nil error.
func (ctx *context) PostValueInt64(name string) (int64, error) {
return ctx.PostValueInt64Default(name, 0.0)
v := ctx.PostValue(name)
if v == "" {
return -1, errUnableToFindPostValue.Format(name)
}
return strconv.ParseInt(v, 10, 64)
}
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as int64.
//
// If not found or parse errors returns the "def".
func (ctx *context) PostValueInt64Default(name string, def int64) int64 {
if v, err := ctx.PostValueInt64(name); err == nil {
return v
}
return def
}
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns the "def".
func (ctx *context) PostValueFloat64Default(name string, def float64) (float64, error) {
// If not found returns -1 and a non-nil error.
func (ctx *context) PostValueFloat64(name string) (float64, error) {
v := ctx.PostValue(name)
if v == "" {
return def, nil
return -1, errUnableToFindPostValue.Format(name)
}
return strconv.ParseFloat(v, 64)
}
@@ -1891,9 +1921,13 @@ func (ctx *context) PostValueFloat64Default(name string, def float64) (float64,
// PostValueInt64Default returns the parsed form data from POST, PATCH,
// or PUT body parameters based on a "name", as float64.
//
// If not found returns 0.0.
func (ctx *context) PostValueFloat64(name string) (float64, error) {
return ctx.PostValueFloat64Default(name, 0.0)
// If not found or parse errors returns the "def".
func (ctx *context) PostValueFloat64Default(name string, def float64) float64 {
if v, err := ctx.PostValueFloat64(name); err == nil {
return v
}
return def
}
// PostValueInt64Default returns the parsed form data from POST, PATCH,
@@ -1901,7 +1935,12 @@ func (ctx *context) PostValueFloat64(name string) (float64, error) {
//
// If not found or value is false, then it returns false, otherwise true.
func (ctx *context) PostValueBool(name string) (bool, error) {
return strconv.ParseBool(ctx.PostValue(name))
v := ctx.PostValue(name)
if v == "" {
return false, errUnableToFindPostValue.Format(name)
}
return strconv.ParseBool(v)
}
// PostValues returns all the parsed form data from POST, PATCH,