|
|
@ -1,17 +1,20 @@
|
|
|
|
package ktgen
|
|
|
|
package ktgen
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/util"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/util"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
var funcsMap=template.FuncMap{
|
|
|
|
|
|
|
|
"lowCamelCase":lowCamelCase,
|
|
|
|
var funcsMap = template.FuncMap{
|
|
|
|
"pathToFuncName":pathToFuncName,
|
|
|
|
"lowCamelCase": lowCamelCase,
|
|
|
|
"parseType":parseType,
|
|
|
|
"pathToFuncName": pathToFuncName,
|
|
|
|
"add":add,
|
|
|
|
"parseType": parseType,
|
|
|
|
|
|
|
|
"add": add,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func lowCamelCase(s string) string {
|
|
|
|
func lowCamelCase(s string) string {
|
|
|
|
if len(s) < 1 {
|
|
|
|
if len(s) < 1 {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
@ -25,27 +28,28 @@ func pathToFuncName(path string) string {
|
|
|
|
path = "/" + path
|
|
|
|
path = "/" + path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
path = strings.Replace(path, "/", "_", -1)
|
|
|
|
path = strings.ReplaceAll(path, "/", "_")
|
|
|
|
path = strings.Replace(path, "-", "_", -1)
|
|
|
|
path = strings.ReplaceAll(path, "-", "_")
|
|
|
|
|
|
|
|
|
|
|
|
camel := util.ToCamelCase(path)
|
|
|
|
camel := util.ToCamelCase(path)
|
|
|
|
return util.ToLower(camel[:1]) + camel[1:]
|
|
|
|
return util.ToLower(camel[:1]) + camel[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func parseType(t string) string {
|
|
|
|
func parseType(t string) string {
|
|
|
|
t=strings.Replace(t,"*","",-1)
|
|
|
|
t = strings.Replace(t, "*", "", -1)
|
|
|
|
if strings.HasPrefix(t,"[]"){
|
|
|
|
if strings.HasPrefix(t, "[]") {
|
|
|
|
return "List<"+parseType(t[2:])+ ">"
|
|
|
|
return "List<" + parseType(t[2:]) + ">"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if strings.HasPrefix(t,"map"){
|
|
|
|
if strings.HasPrefix(t, "map") {
|
|
|
|
tys,e:=util.DecomposeType(t)
|
|
|
|
tys, e := util.DecomposeType(t)
|
|
|
|
if e!=nil{
|
|
|
|
if e != nil {
|
|
|
|
log.Fatal(e)
|
|
|
|
log.Fatal(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(tys)!=2{
|
|
|
|
if len(tys) != 2 {
|
|
|
|
log.Fatal("Map type number !=2")
|
|
|
|
log.Fatal("Map type number !=2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "Map<String,"+parseType(tys[1])+">"
|
|
|
|
return "Map<String," + parseType(tys[1]) + ">"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch t {
|
|
|
|
switch t {
|
|
|
@ -62,6 +66,6 @@ func parseType(t string) string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func add(a,i int)int{
|
|
|
|
func add(a, i int) int {
|
|
|
|
return a+i
|
|
|
|
return a + i
|
|
|
|
}
|
|
|
|
}
|
|
|
|