Skip to content

Commit

Permalink
optimized (zeromicro#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingxt authored Jan 15, 2021
1 parent 6887fb2 commit 4db2067
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion tools/goctl/api/gogen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -110,6 +112,7 @@ func getMiddleware(api *spec.ApiSpec) []string {
}
}
}

return result.KeysStr()
}

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/api/javagen/gencomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,6 @@ func formatSource(source string) string {
if err := scanner.Err(); err != nil {
fmt.Println(err)
}

return builder.String()
}
1 change: 1 addition & 0 deletions tools/goctl/api/javagen/genpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 4 additions & 0 deletions tools/goctl/api/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (p parser) convert2Spec() error {
if err != nil {
return err
}

return p.fillService()
}

Expand Down Expand Up @@ -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))
}

Expand All @@ -203,6 +205,7 @@ func (p parser) commentExprs(comment ast.Expr) string {
if comment == nil {
return ""
}

return comment.Text()
}

Expand Down Expand Up @@ -310,5 +313,6 @@ func (p parser) fillRouteType(route *spec.Route) error {
route.ResponseType = *tp
}
}

return nil
}
2 changes: 2 additions & 0 deletions tools/goctl/api/spec/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ func (r Route) GetAnnotation(key string) string {
if r.Annotation.Properties == nil {
return ""
}

return r.Annotation.Properties[key]
}

func (g Group) GetAnnotation(key string) string {
if g.Annotation.Properties == nil {
return ""
}

return g.Annotation.Properties[key]
}

Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/goctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

var (
BuildVersion = "1.1.3"
BuildVersion = "1.1.4"
commands = []cli.Command{
{
Name: "upgrade",
Expand Down

0 comments on commit 4db2067

Please sign in to comment.