Skip to content

Commit

Permalink
fix: some reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF committed Dec 16, 2022
1 parent aa7eb43 commit 48fba4d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func Init() *cli.App {
},
{
Name: meta.CmdClient,
Usage: "Generate hertz client based IDL",
Usage: "Generate hertz client based on IDL",
Flags: []cli.Flag{
&idlFlag,
&moduleFlag,
Expand Down
3 changes: 1 addition & 2 deletions cmd/hz/generator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (pkgGen *HttpPackageGenerator) genClient(pkg *HttpPackage, clientDir string
return err
}
}
var client ClientFile
client = ClientFile{
client := ClientFile{
FilePath: filepath.Join(clientDir, util.ToSnakeCase(s.Name)+".go"),
ServiceName: util.ToSnakeCase(s.Name),
ClientMethods: s.ClientMethods,
Expand Down
5 changes: 5 additions & 0 deletions cmd/hz/meta/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ type Backend string
const (
BackendGolang Backend = "golang"
)

// template const value
const (
SetBodyParam = "setBodyParam(req).\n"
)
11 changes: 4 additions & 7 deletions cmd/hz/protobuf/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,13 @@ func astToService(ast *descriptorpb.FileDescriptorProto, resolver *Resolver, arg
Name: s.GetName(),
}

baseDomain := ""
service.BaseDomain = ""
domainAnno := checkFirstOption(api.E_BaseDomain, s.GetOptions())
if args.CmdType == meta.CmdClient {
val, ok := domainAnno.(string)
if !ok || len(val) == 0 {
baseDomain = ""
} else {
baseDomain = val
if ok && len(val) != 0 {
service.BaseDomain = val
}
service.BaseDomain = baseDomain
}

ms := s.GetMethod()
Expand Down Expand Up @@ -275,7 +272,7 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, gen *protogen
clientMethod.FormFileCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
}
}
clientMethod.BodyParamsCode = "setBodyParam(req).\n"
clientMethod.BodyParamsCode = meta.SetBodyParam
if hasBodyAnnotation && hasFormAnnotation {
clientMethod.FormValueCode = ""
clientMethod.FormFileCode = ""
Expand Down
9 changes: 4 additions & 5 deletions cmd/hz/thrift/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ func astToService(ast *parser.Thrift, resolver *Resolver, args *config.Argument)
service := &generator.Service{
Name: s.GetName(),
}
baseDomain := ""
service.BaseDomain = ""
domainAnno := getAnnotation(s.Annotations, ApiBaseDomain)
if len(domainAnno) == 1 {
baseDomain = domainAnno[0]
if args.CmdType == meta.CmdClient {
service.BaseDomain = baseDomain
service.BaseDomain = domainAnno[0]
}
}

Expand Down Expand Up @@ -98,7 +97,7 @@ func astToService(ast *parser.Thrift, resolver *Resolver, args *config.Argument)
var reqName string
if len(m.Arguments) >= 1 {
if len(m.Arguments) > 1 {
return nil, fmt.Errorf("function '%s' has more than one argument, but only the first can be used in hertz now", m.GetName())
logs.Warnf("function '%s' has more than one argument, but only the first can be used in hertz now", m.GetName())
}
rt, err := resolver.ResolveIdentifier(m.Arguments[0].GetType().GetName())
if err != nil {
Expand Down Expand Up @@ -234,7 +233,7 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, p *parser.Typ
}
}
}
clientMethod.BodyParamsCode = "setBodyParam(req).\n"
clientMethod.BodyParamsCode = meta.SetBodyParam
if hasBodyAnnotation && hasFormAnnotation {
clientMethod.FormValueCode = ""
clientMethod.FormFileCode = ""
Expand Down

0 comments on commit 48fba4d

Please sign in to comment.