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

add uint8 parameter type, and mvc and hero - this commit may be a point of tutorial on how to add a completely new type from scratch to the hero for future contributors

Former-commit-id: dc7a7e6c97ef0c644a22e92072e4bdb98ae10582
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-08-24 00:56:54 +03:00
parent ef5f383227
commit cbd8fe95ac
12 changed files with 200 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ func registerBuiltinsMacroFuncs(out *macro.Map) {
registerStringMacroFuncs(out.String)
registerNumberMacroFuncs(out.Number)
registerInt64MacroFuncs(out.Int64)
registerUint8MacroFuncs(out.Uint8)
registerUint64MacroFuncs(out.Uint64)
registerAlphabeticalMacroFuncs(out.Alphabetical)
registerFileMacroFuncs(out.File)
@@ -176,6 +177,51 @@ func registerInt64MacroFuncs(out *macro.Macro) {
})
}
// Uint8
// 0 to 255.
func registerUint8MacroFuncs(out *macro.Macro) {
// checks if the param value's uint8 representation is
// bigger or equal than 'min'
out.RegisterFunc("min", func(min uint8) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 8)
if err != nil {
return false
}
return uint8(n) >= min
}
})
// checks if the param value's uint8 representation is
// smaller or equal than 'max'
out.RegisterFunc("max", func(max uint8) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 8)
if err != nil {
return false
}
return uint8(n) <= max
}
})
// checks if the param value's uint8 representation is
// between min and max, including 'min' and 'max'
out.RegisterFunc("range", func(min, max uint8) macro.EvaluatorFunc {
return func(paramValue string) bool {
n, err := strconv.ParseUint(paramValue, 10, 8)
if err != nil {
return false
}
if v := uint8(n); v < min || v > max {
return false
}
return true
}
})
}
// Uint64
// 0 to 18446744073709551615.
func registerUint64MacroFuncs(out *macro.Macro) {