From 4db20677f7479b36474020edbb7ec62078b6764c Mon Sep 17 00:00:00 2001 From: kingxt Date: Fri, 15 Jan 2021 11:36:37 +0800 Subject: [PATCH] optimized (#392) --- tools/goctl/api/gogen/util.go | 13 ++++++++++++- tools/goctl/api/javagen/gencomponents.go | 1 + tools/goctl/api/javagen/genpacket.go | 1 + tools/goctl/api/parser/parser.go | 4 ++++ tools/goctl/api/spec/fn.go | 2 ++ tools/goctl/goctl.go | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/goctl/api/gogen/util.go b/tools/goctl/api/gogen/util.go index 7557a7e6..b327ed26 100644 --- a/tools/goctl/api/gogen/util.go +++ b/tools/goctl/api/gogen/util.go @@ -69,6 +69,7 @@ func getParentPackage(dir string) (string, error) { if err != nil { return "", err } + return filepath.ToSlash(filepath.Join(projectCtx.Path, strings.TrimPrefix(projectCtx.WorkDir, projectCtx.Dir))), nil } @@ -82,6 +83,7 @@ func writeProperty(writer io.Writer, name, tag, comment string, tp spec.Type, in } else { _, err = fmt.Fprintf(writer, "%s %s %s\n", strings.Title(name), tp.Name(), tag) } + return err } @@ -110,6 +112,7 @@ func getMiddleware(api *spec.ApiSpec) []string { } } } + return result.KeysStr() } @@ -127,7 +130,15 @@ func responseGoTypeName(r spec.Route, pkg ...string) string { return "" } - return golangExpr(r.ResponseType, pkg...) + resp := golangExpr(r.ResponseType, pkg...) + switch r.ResponseType.(type) { + case spec.DefineStruct: + if !strings.HasPrefix(resp, "*") { + return "*" + resp + } + } + + return resp } func requestGoTypeName(r spec.Route, pkg ...string) string { diff --git a/tools/goctl/api/javagen/gencomponents.go b/tools/goctl/api/javagen/gencomponents.go index a619d0d8..952d4e50 100644 --- a/tools/goctl/api/javagen/gencomponents.go +++ b/tools/goctl/api/javagen/gencomponents.go @@ -339,5 +339,6 @@ func formatSource(source string) string { if err := scanner.Err(); err != nil { fmt.Println(err) } + return builder.String() } diff --git a/tools/goctl/api/javagen/genpacket.go b/tools/goctl/api/javagen/genpacket.go index 2f37d1f1..d5dc94b1 100644 --- a/tools/goctl/api/javagen/genpacket.go +++ b/tools/goctl/api/javagen/genpacket.go @@ -128,6 +128,7 @@ func getImports(api *spec.ApiSpec, packetName string) string { if len(allTypes) > 0 { fmt.Fprintf(&builder, "import com.xhb.logic.http.packet.%s.model.*;\n", packetName) } + return builder.String() } diff --git a/tools/goctl/api/parser/parser.go b/tools/goctl/api/parser/parser.go index 1943b8d5..bd7a3330 100644 --- a/tools/goctl/api/parser/parser.go +++ b/tools/goctl/api/parser/parser.go @@ -58,6 +58,7 @@ func (p parser) convert2Spec() error { if err != nil { return err } + return p.fillService() } @@ -188,6 +189,7 @@ func (p parser) astTypeToSpec(in ast.DataType) spec.Type { return spec.PointerType{RawName: v.PointerExpr.Text(), Type: spec.DefineStruct{RawName: raw}} } } + panic(fmt.Sprintf("unspported type %+v", in)) } @@ -203,6 +205,7 @@ func (p parser) commentExprs(comment ast.Expr) string { if comment == nil { return "" } + return comment.Text() } @@ -310,5 +313,6 @@ func (p parser) fillRouteType(route *spec.Route) error { route.ResponseType = *tp } } + return nil } diff --git a/tools/goctl/api/spec/fn.go b/tools/goctl/api/spec/fn.go index 41c9ad79..c5c7a8c8 100644 --- a/tools/goctl/api/spec/fn.go +++ b/tools/goctl/api/spec/fn.go @@ -170,6 +170,7 @@ func (r Route) GetAnnotation(key string) string { if r.Annotation.Properties == nil { return "" } + return r.Annotation.Properties[key] } @@ -177,6 +178,7 @@ func (g Group) GetAnnotation(key string) string { if g.Annotation.Properties == nil { return "" } + return g.Annotation.Properties[key] } diff --git a/tools/goctl/goctl.go b/tools/goctl/goctl.go index 2406b3ad..dc138f38 100644 --- a/tools/goctl/goctl.go +++ b/tools/goctl/goctl.go @@ -28,7 +28,7 @@ import ( ) var ( - BuildVersion = "1.1.3" + BuildVersion = "1.1.4" commands = []cli.Command{ { Name: "upgrade",