mirror of
https://github.com/kataras/iris.git
synced 2026-01-19 18:05:58 +00:00
Update to 8.4.0 | New macro type, new high-optimized MVC features. Read HISTORY.md
Former-commit-id: b72a23ba063be60a9750c8b1b0df024b0c8ed549
This commit is contained in:
@@ -21,6 +21,10 @@ const (
|
||||
// Allows only numbers (0-9)
|
||||
// Declaration: /mypath/{myparam:int}
|
||||
ParamTypeInt
|
||||
// ParamTypeLong is the integer, a number type.
|
||||
// Allows only numbers (0-9)
|
||||
// Declaration: /mypath/{myparam:long}
|
||||
ParamTypeLong
|
||||
// ParamTypeAlphabetical is the alphabetical/letter type type.
|
||||
// Allows letters only (upper or lowercase)
|
||||
// Declaration: /mypath/{myparam:alphabetical}
|
||||
@@ -44,6 +48,7 @@ const (
|
||||
var paramTypes = map[string]ParamType{
|
||||
"string": ParamTypeString,
|
||||
"int": ParamTypeInt,
|
||||
"long": ParamTypeLong,
|
||||
"alphabetical": ParamTypeAlphabetical,
|
||||
"file": ParamTypeFile,
|
||||
"path": ParamTypePath,
|
||||
|
||||
@@ -60,6 +60,7 @@ func TestParseParam(t *testing.T) {
|
||||
},
|
||||
ErrorCode: 404,
|
||||
}}, // 0
|
||||
|
||||
{true,
|
||||
ast.ParamStatement{
|
||||
Src: "{id:int range(1,5)}",
|
||||
@@ -123,6 +124,13 @@ func TestParseParam(t *testing.T) {
|
||||
},
|
||||
ErrorCode: 404,
|
||||
}}, // 7
|
||||
{true,
|
||||
ast.ParamStatement{
|
||||
Src: "{id:long else 404}",
|
||||
Name: "id",
|
||||
Type: ast.ParamTypeLong,
|
||||
ErrorCode: 404,
|
||||
}}, // 8
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ func (m *Macro) getFunc(funcName string) ParamEvaluatorBuilder {
|
||||
|
||||
// Map contains the default macros mapped to their types.
|
||||
// This is the manager which is used by the caller to register custom
|
||||
// parameter functions per param-type (String, Int, Alphabetical, File, Path).
|
||||
// parameter functions per param-type (String, Int, Long, Alphabetical, File, Path).
|
||||
type Map struct {
|
||||
// string type
|
||||
// anything
|
||||
@@ -216,6 +216,9 @@ type Map struct {
|
||||
// int type
|
||||
// only numbers (0-9)
|
||||
Int *Macro
|
||||
// long an int64 type
|
||||
// only numbers (0-9)
|
||||
Long *Macro
|
||||
// alphabetical/letter type
|
||||
// letters only (upper or lowercase)
|
||||
Alphabetical *Macro
|
||||
@@ -241,6 +244,7 @@ func NewMap() *Map {
|
||||
// it allows everything, so no need for a regexp here.
|
||||
String: newMacro(func(string) bool { return true }),
|
||||
Int: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
Long: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
Alphabetical: newMacro(MustNewEvaluatorFromRegexp("^[a-zA-Z ]+$")),
|
||||
File: newMacro(MustNewEvaluatorFromRegexp("^[a-zA-Z0-9_.-]*$")),
|
||||
// it allows everything, we have String and Path as different
|
||||
@@ -259,6 +263,8 @@ func (m *Map) Lookup(typ ast.ParamType) *Macro {
|
||||
switch typ {
|
||||
case ast.ParamTypeInt:
|
||||
return m.Int
|
||||
case ast.ParamTypeLong:
|
||||
return m.Long
|
||||
case ast.ParamTypeAlphabetical:
|
||||
return m.Alphabetical
|
||||
case ast.ParamTypeFile:
|
||||
|
||||
Reference in New Issue
Block a user