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
|
||||
|
||||
Reference in New Issue
Block a user