feat: update route generate
This commit is contained in:
@@ -67,31 +67,29 @@ func Render(path string, routes []RouteDefinition) error {
|
||||
Action: action.Name,
|
||||
Func: funcName,
|
||||
Params: lo.FilterMap(action.Params, func(item ParamDefinition, _ int) (string, bool) {
|
||||
key := item.Name
|
||||
if item.Key != "" {
|
||||
key = item.Key
|
||||
}
|
||||
|
||||
switch item.Position {
|
||||
case PositionQuery:
|
||||
return fmt.Sprintf(`Query%s[%s]("%s")`, isScalarType(item.Type), item.Type, item.Name), true
|
||||
return fmt.Sprintf(`Query%s[%s]("%s")`, isScalarType(item.Type), item.Type, key), true
|
||||
case PositionHeader:
|
||||
return fmt.Sprintf(`Header[%s]("%s")`, item.Type, item.Name), true
|
||||
return fmt.Sprintf(`Header[%s]("%s")`, item.Type, key), true
|
||||
case PositionFile:
|
||||
return fmt.Sprintf(`File[multipart.FileHeader]("%s")`, key), true
|
||||
case PositionCookie:
|
||||
key := item.Name
|
||||
if item.Key != "" {
|
||||
key = item.Key
|
||||
}
|
||||
|
||||
if item.Type == "string" {
|
||||
return fmt.Sprintf(`CookieParam("%s")`, key), true
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`Cookie[%s]("%s")`, item.Type, key), true
|
||||
case PositionBody:
|
||||
return fmt.Sprintf(`Body[%s]("%s")`, item.Type, item.Name), true
|
||||
return fmt.Sprintf(`Body[%s]("%s")`, item.Type, key), true
|
||||
case PositionPath:
|
||||
return fmt.Sprintf(`Path%s[%s]("%s")`, isScalarType(item.Type), item.Type, item.Name), true
|
||||
return fmt.Sprintf(`Path%s[%s]("%s")`, isScalarType(item.Type), item.Type, key), true
|
||||
case PositionLocal:
|
||||
key := item.Name
|
||||
if item.Key != "" {
|
||||
key = item.Key
|
||||
}
|
||||
return fmt.Sprintf(`Local[%s]("%s")`, item.Type, key), true
|
||||
}
|
||||
return "", false
|
||||
|
||||
@@ -53,6 +53,8 @@ func positionFromString(v string) Position {
|
||||
return PositionCookie
|
||||
case "local":
|
||||
return PositionLocal
|
||||
case "file":
|
||||
return PositionFile
|
||||
}
|
||||
panic("invalid position: " + v)
|
||||
}
|
||||
@@ -64,6 +66,7 @@ const (
|
||||
PositionHeader Position = "header"
|
||||
PositionCookie Position = "cookie"
|
||||
PositionLocal Position = "local"
|
||||
PositionFile Position = "file"
|
||||
)
|
||||
|
||||
func ParseFile(file string) []RouteDefinition {
|
||||
|
||||
Reference in New Issue
Block a user