mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-21 14:45:02 +00:00
Merge pull request #115 from runner-mei/master
add support to map as a argument in the controller action
This commit is contained in:
@@ -17,8 +17,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/revel/revel"
|
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/revel/revel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SourceInfo is the top-level struct containing all extracted information
|
// SourceInfo is the top-level struct containing all extracted information
|
||||||
@@ -782,6 +783,13 @@ func NewTypeExpr(pkgName string, expr ast.Expr) TypeExpr {
|
|||||||
case *ast.ArrayType:
|
case *ast.ArrayType:
|
||||||
e := NewTypeExpr(pkgName, t.Elt)
|
e := NewTypeExpr(pkgName, t.Elt)
|
||||||
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
||||||
|
case *ast.MapType:
|
||||||
|
if identKey, ok := t.Key.(*ast.Ident); ok && IsBuiltinType(identKey.Name) {
|
||||||
|
e := NewTypeExpr(pkgName, t.Value)
|
||||||
|
return TypeExpr{"map[" + identKey.Name + "]" + e.Expr, e.PkgName, e.pkgIndex + len("map["+identKey.Name+"]"), e.Valid}
|
||||||
|
}
|
||||||
|
|
||||||
|
revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.")
|
||||||
case *ast.Ellipsis:
|
case *ast.Ellipsis:
|
||||||
e := NewTypeExpr(pkgName, t.Elt)
|
e := NewTypeExpr(pkgName, t.Elt)
|
||||||
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid}
|
||||||
|
|||||||
@@ -94,18 +94,20 @@ func TestGetValidationKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var TypeExprs = map[string]TypeExpr{
|
var TypeExprs = map[string]TypeExpr{
|
||||||
"int": {"int", "", 0, true},
|
"int": {"int", "", 0, true},
|
||||||
"*int": {"*int", "", 1, true},
|
"*int": {"*int", "", 1, true},
|
||||||
"[]int": {"[]int", "", 2, true},
|
"[]int": {"[]int", "", 2, true},
|
||||||
"...int": {"[]int", "", 2, true},
|
"...int": {"[]int", "", 2, true},
|
||||||
"[]*int": {"[]*int", "", 3, true},
|
"[]*int": {"[]*int", "", 3, true},
|
||||||
"...*int": {"[]*int", "", 3, true},
|
"...*int": {"[]*int", "", 3, true},
|
||||||
"MyType": {"MyType", "pkg", 0, true},
|
"MyType": {"MyType", "pkg", 0, true},
|
||||||
"*MyType": {"*MyType", "pkg", 1, true},
|
"*MyType": {"*MyType", "pkg", 1, true},
|
||||||
"[]MyType": {"[]MyType", "pkg", 2, true},
|
"[]MyType": {"[]MyType", "pkg", 2, true},
|
||||||
"...MyType": {"[]MyType", "pkg", 2, true},
|
"...MyType": {"[]MyType", "pkg", 2, true},
|
||||||
"[]*MyType": {"[]*MyType", "pkg", 3, true},
|
"[]*MyType": {"[]*MyType", "pkg", 3, true},
|
||||||
"...*MyType": {"[]*MyType", "pkg", 3, true},
|
"...*MyType": {"[]*MyType", "pkg", 3, true},
|
||||||
|
"map[int]MyType": {"map[int]MyType", "pkg", 8, true},
|
||||||
|
"map[int]*MyType": {"map[int]*MyType", "pkg", 9, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTypeExpr(t *testing.T) {
|
func TestTypeExpr(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user