1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 12:57:05 +00:00

New ':int64' and ':uint64' route path parameters - and - support the new uint64 for MVC (int64 was already supported there) - and - add ctx.Params().GetUint64 (GetInt64 was already there) - and - make the ':int or :number' to accept negative numbers with no digit limit (at low level) and rename the 'app.Macros().Int.RegisterFunc' to 'Number.RegisterFunc' because number can be any type of number not only standard go type limited - and - add alias for ':boolean' -> ':bool'. Finally, Update the examples but not the version yet, I have to provide a good README table to explain the end-developers how they can benefit by those changes and why the breaking change (which is to accept negative numbers via ':int') is for their own good and how they can make their own macro functions so they do not depend on the Iris builtn macro funcs only. More to come tomorrow, stay tuned

Former-commit-id: 3601abfc89478185afec3594375080778214283e
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-08-23 06:30:12 +03:00
parent 01b5f6089d
commit b019a281eb
28 changed files with 478 additions and 242 deletions

View File

@@ -35,8 +35,9 @@ func registerBuiltinsMacroFuncs(out *macro.Map) {
//
// these can be overridden by the user, later on.
registerStringMacroFuncs(out.String)
registerIntMacroFuncs(out.Int)
registerIntMacroFuncs(out.Long)
registerNumberMacroFuncs(out.Number)
registerInt64MacroFuncs(out.Int64)
registerUint64MacroFuncs(out.Uint64)
registerAlphabeticalMacroFuncs(out.Alphabetical)
registerFileMacroFuncs(out.File)
registerPathMacroFuncs(out.Path)
@@ -87,9 +88,9 @@ func registerStringMacroFuncs(out *macro.Macro) {
})
}
// Int
// only numbers (0-9)
func registerIntMacroFuncs(out *macro.Macro) {
// Number
// positive and negative numbers, number of digits depends on the arch.
func registerNumberMacroFuncs(out *macro.Macro) {
// checks if the param value's int representation is
// bigger or equal than 'min'
out.RegisterFunc("min", func(min int) macro.EvaluatorFunc {
@@ -131,6 +132,94 @@ func registerIntMacroFuncs(out *macro.Macro) {
})
}
// Int64
// -9223372036854775808 to 9223372036854775807.
func registerInt64MacroFuncs(out *macro.Macro) {
// checks if the param value's int64 representation is
// bigger or equal than 'min'
out.RegisterFunc("min", func(min int64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseInt(paramValue, 10, 64)
if err != nil {
return false
}
return n >= min
}
})
// checks if the param value's int64 representation is
// smaller or equal than 'max'
out.RegisterFunc("max", func(max int64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseInt(paramValue, 10, 64)
if err != nil {
return false
}
return n <= max
}
})
// checks if the param value's int64 representation is
// between min and max, including 'min' and 'max'
out.RegisterFunc("range", func(min, max int64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseInt(paramValue, 10, 64)
if err != nil {
return false
}
if n < min || n > max {
return false
}
return true
}
})
}
// Uint64
// 0 to 18446744073709551615.
func registerUint64MacroFuncs(out *macro.Macro) {
// checks if the param value's uint64 representation is
// bigger or equal than 'min'
out.RegisterFunc("min", func(min uint64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 64)
if err != nil {
return false
}
return n >= min
}
})
// checks if the param value's uint64 representation is
// smaller or equal than 'max'
out.RegisterFunc("max", func(max uint64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 64)
if err != nil {
return false
}
return n <= max
}
})
// checks if the param value's uint64 representation is
// between min and max, including 'min' and 'max'
out.RegisterFunc("range", func(min, max uint64) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 64)
if err != nil {
return false
}
if n < min || n > max {
return false
}
return true
}
})
}
// Alphabetical
// letters only (upper or lowercase)
func registerAlphabeticalMacroFuncs(out *macro.Macro) {