goctl生成Kotlin代码优化 (#16)

* 修复Kotlin连接失败抛出Exception;添加Kotlin连接超时

* 修复路径参数导致生成的Kotlin函数名带有:问题

* Added HTTP Patch Method

* kotlin-add-patch-support

* format-imports
This commit is contained in:
Steven Zack
2020-08-18 21:49:31 +08:00
committed by GitHub
parent 054d9b5540
commit 1252bd9cde
3 changed files with 28 additions and 20 deletions

View File

@@ -5,15 +5,16 @@ import (
"strings"
"text/template"
"github.com/iancoleman/strcase"
"github.com/tal-tech/go-zero/tools/goctl/api/util"
)
var funcsMap = template.FuncMap{
"lowCamelCase": lowCamelCase,
"pathToFuncName": pathToFuncName,
"parseType": parseType,
"add": add,
"upperCase": upperCase,
"lowCamelCase": lowCamelCase,
"routeToFuncName": routeToFuncName,
"parseType": parseType,
"add": add,
"upperCase": upperCase,
}
func lowCamelCase(s string) string {
@@ -24,16 +25,16 @@ func lowCamelCase(s string) string {
return util.ToLower(s[:1]) + s[1:]
}
func pathToFuncName(path string) string {
func routeToFuncName(method, path string) string {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
path = strings.ReplaceAll(path, "/", "_")
path = strings.ReplaceAll(path, "-", "_")
path = strings.ReplaceAll(path, ":", "With_")
camel := util.ToCamelCase(path)
return util.ToLower(camel[:1]) + camel[1:]
return strings.ToLower(method)+strcase.ToCamel(path)
}
func parseType(t string) string {