fix: bind issues
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -37,7 +37,7 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"gen",
|
"gen",
|
||||||
"route",
|
"route",
|
||||||
"/projects/learn/qq",
|
"/projects/qvyun/backend",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ func Render(path string, routes []RouteDefinition) error {
|
|||||||
return fmt.Sprintf(`Body[%s]("%s")`, item.Type, item.Name), true
|
return fmt.Sprintf(`Body[%s]("%s")`, item.Type, item.Name), true
|
||||||
case PositionPath:
|
case PositionPath:
|
||||||
return fmt.Sprintf(`Path[%s]("%s")`, item.Type, item.Name), true
|
return fmt.Sprintf(`Path[%s]("%s")`, item.Type, item.Name), true
|
||||||
|
case PositionLocal:
|
||||||
|
key := item.Name
|
||||||
|
if item.Key != "" {
|
||||||
|
key = item.Key
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(`Local[%s]("%s")`, item.Type, key), true
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ func positionFromString(v string) Position {
|
|||||||
return PositionHeader
|
return PositionHeader
|
||||||
case "cookie":
|
case "cookie":
|
||||||
return PositionCookie
|
return PositionCookie
|
||||||
|
case "local":
|
||||||
|
return PositionLocal
|
||||||
}
|
}
|
||||||
panic("invalid position: " + v)
|
panic("invalid position: " + v)
|
||||||
}
|
}
|
||||||
@@ -64,6 +66,7 @@ const (
|
|||||||
PositionBody Position = "body"
|
PositionBody Position = "body"
|
||||||
PositionHeader Position = "header"
|
PositionHeader Position = "header"
|
||||||
PositionCookie Position = "cookie"
|
PositionCookie Position = "cookie"
|
||||||
|
PositionLocal Position = "local"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseFile(file string) []RouteDefinition {
|
func ParseFile(file string) []RouteDefinition {
|
||||||
@@ -175,11 +178,14 @@ func ParseFile(file string) []RouteDefinition {
|
|||||||
usedImports[recvType] = append(usedImports[recvType], imports[pkgName[0]])
|
usedImports[recvType] = append(usedImports[recvType], imports[pkgName[0]])
|
||||||
}
|
}
|
||||||
|
|
||||||
typ = strings.TrimPrefix(typ, "*")
|
|
||||||
|
|
||||||
for _, name := range param.Names {
|
for _, name := range param.Names {
|
||||||
for i, bindParam := range bindParams {
|
for i, bindParam := range bindParams {
|
||||||
if bindParam.Name == name.Name {
|
if bindParam.Name == name.Name {
|
||||||
|
|
||||||
|
if bindParams[i].Position != PositionLocal {
|
||||||
|
typ = strings.TrimPrefix(typ, "*")
|
||||||
|
}
|
||||||
|
|
||||||
bindParams[i].Type = typ
|
bindParams[i].Type = typ
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user