1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-22 03:15:58 +00:00

Conversion once at macros and their functions, internal changes required

Former-commit-id: 7b778cccfb7c0e30ca5e8106017ada065993aba5
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-09-27 03:17:45 +03:00
parent dc3c38b189
commit d6d27b2605
11 changed files with 338 additions and 279 deletions

View File

@@ -6,6 +6,7 @@
package memstore
import (
"fmt"
"reflect"
"strconv"
"strings"
@@ -67,11 +68,19 @@ func (e Entry) GetByKindOrNil(k reflect.Kind) interface{} {
// If not found returns "def".
func (e Entry) StringDefault(def string) string {
v := e.ValueRaw
if v == nil {
return def
}
if vString, ok := v.(string); ok {
return vString
}
val := fmt.Sprintf("%v", v)
if val != "" {
return val
}
return def
}
@@ -105,6 +114,20 @@ func (e Entry) IntDefault(def int) (int, error) {
return val, nil
case int:
return vv, nil
case int8:
return int(vv), nil
case int32:
return int(vv), nil
case int64:
return int(vv), nil
case uint:
return int(vv), nil
case uint8:
return int(vv), nil
case uint32:
return int(vv), nil
case uint64:
return int(vv), nil
}
return def, errFindParse.Format("int", e.Key)
@@ -123,6 +146,10 @@ func (e Entry) Int64Default(def int64) (int64, error) {
return strconv.ParseInt(vv, 10, 64)
case int64:
return vv, nil
case int32:
return int64(vv), nil
case int8:
return int64(vv), nil
case int:
return int64(vv), nil
}
@@ -151,6 +178,12 @@ func (e Entry) Float64Default(def float64) (float64, error) {
return vv, nil
case int:
return float64(vv), nil
case int64:
return float64(vv), nil
case uint:
return float64(vv), nil
case uint64:
return float64(vv), nil
}
return def, errFindParse.Format("float64", e.Key)