fix bug: release empty struct limit (#96)

master
Keson 4 years ago committed by GitHub
parent b628bc0086
commit 9f9c24cce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,24 +57,24 @@ var errJsonConvert = errors.New("json convert error")
{{.types}} {{.types}}
` `
callInterfaceFunctionTemplate = `{{if .hasComment}}{{.comment}} callInterfaceFunctionTemplate = `{{if .hasComment}}{{.comment}}
{{end}}{{.method}}(ctx context.Context,in *{{.pbRequest}}) {{if .hasResponse}}(*{{.pbResponse}},{{end}} error{{if .hasResponse}}){{end}}` {{end}}{{.method}}(ctx context.Context,in *{{.pbRequest}}) (*{{.pbResponse}},error)`
callFunctionTemplate = ` callFunctionTemplate = `
{{if .hasComment}}{{.comment}}{{end}} {{if .hasComment}}{{.comment}}{{end}}
func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRequest}}) {{if .hasResponse}}(*{{.pbResponse}},{{end}} error{{if .hasResponse}}){{end}} { func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRequest}}) (*{{.pbResponse}}, error) {
var request {{.package}}.{{.pbRequest}} var request {{.package}}.{{.pbRequest}}
bts, err := jsonx.Marshal(in) bts, err := jsonx.Marshal(in)
if err != nil { if err != nil {
return {{if .hasResponse}}nil, {{end}}errJsonConvert return nil, errJsonConvert
} }
err = jsonx.Unmarshal(bts, &request) err = jsonx.Unmarshal(bts, &request)
if err != nil { if err != nil {
return {{if .hasResponse}}nil, {{end}}errJsonConvert return nil, errJsonConvert
} }
client := {{.package}}.New{{.rpcServiceName}}Client(m.cli.Conn()) client := {{.package}}.New{{.rpcServiceName}}Client(m.cli.Conn())
{{if .hasResponse}}resp, err := {{else}}_, err = {{end}}client.{{.method}}(ctx, &request) resp, err := client.{{.method}}(ctx, &request)
{{if .hasResponse}}if err != nil{ if err != nil{
return nil, err return nil, err
} }
@ -89,11 +89,7 @@ func (m *default{{.rpcServiceName}}) {{.method}}(ctx context.Context,in *{{.pbRe
return nil, errJsonConvert return nil, errJsonConvert
} }
return &ret, nil{{else}}if err != nil { return &ret, nil
return err
}
return nil{{end}}
} }
` `
) )
@ -177,10 +173,6 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
pkgName := file.Package pkgName := file.Package
functions := make([]string, 0) functions := make([]string, 0)
for _, method := range service.Funcs { for _, method := range service.Funcs {
data, found := file.Strcuts[strings.ToLower(method.OutType)]
if found {
found = len(data.Field) > 0
}
var comment string var comment string
if len(method.Document) > 0 { if len(method.Document) > 0 {
comment = method.Document[0] comment = method.Document[0]
@ -191,7 +183,6 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
"package": pkgName, "package": pkgName,
"pbRequest": method.InType, "pbRequest": method.InType,
"pbResponse": method.OutType, "pbResponse": method.OutType,
"hasResponse": found,
"hasComment": len(method.Document) > 0, "hasComment": len(method.Document) > 0,
"comment": comment, "comment": comment,
}) })
@ -205,26 +196,20 @@ func (g *defaultRpcGenerator) getFuncs(service *parser.RpcService) ([]string, er
} }
func (g *defaultRpcGenerator) getInterfaceFuncs(service *parser.RpcService) ([]string, error) { func (g *defaultRpcGenerator) getInterfaceFuncs(service *parser.RpcService) ([]string, error) {
file := g.ast
functions := make([]string, 0) functions := make([]string, 0)
for _, method := range service.Funcs { for _, method := range service.Funcs {
data, found := file.Strcuts[strings.ToLower(method.OutType)]
if found {
found = len(data.Field) > 0
}
var comment string var comment string
if len(method.Document) > 0 { if len(method.Document) > 0 {
comment = method.Document[0] comment = method.Document[0]
} }
buffer, err := util.With("interfaceFn").Parse(callInterfaceFunctionTemplate).Execute( buffer, err := util.With("interfaceFn").Parse(callInterfaceFunctionTemplate).Execute(
map[string]interface{}{ map[string]interface{}{
"hasComment": len(method.Document) > 0, "hasComment": len(method.Document) > 0,
"comment": comment, "comment": comment,
"method": method.Name.Title(), "method": method.Name.Title(),
"pbRequest": method.InType, "pbRequest": method.InType,
"pbResponse": method.OutType, "pbResponse": method.OutType,
"hasResponse": found,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -445,9 +445,6 @@ func (a *PbAst) GenTypesCode() (string, error) {
} }
func (s *Struct) genCode(containsTypeStatement bool) (string, error) { func (s *Struct) genCode(containsTypeStatement bool) (string, error) {
if len(s.Field) == 0 {
return "", nil
}
fields := make([]string, 0) fields := make([]string, 0)
for _, f := range s.Field { for _, f := range s.Field {
var comment, doc string var comment, doc string

Loading…
Cancel
Save