From 4a511192617d8af994412f2bcc27f4c1f0639c65 Mon Sep 17 00:00:00 2001 From: Eli Yukelzon Date: Wed, 8 Apr 2020 12:51:45 +0300 Subject: [PATCH] fix for named return parameters --- .gitignore | 2 ++ main.go | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 66fd13c..aff6cf6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ # Dependency directories (remove the comment below to include it) # vendor/ +main +.vscode/launch.json diff --git a/main.go b/main.go index 56b3fad..2838c59 100644 --- a/main.go +++ b/main.go @@ -62,16 +62,17 @@ func functionDef(fun *ast.FuncDecl, fset *token.FileSet) string { if err != nil { log.Fatalf("failed printing %s", err) } - - returns = append(returns, typeNameBuf.String()) + if len(r.Names) > 0 { + for _, k := range r.Names { + returns = append(returns, fmt.Sprintf("%s %s", k.Name, typeNameBuf.String())) + } + } else { + returns = append(returns, typeNameBuf.String()) + } } } - returnString := "" - if len(returns) == 1 { - returnString = returns[0] - } else if len(returns) > 1 { - returnString = fmt.Sprintf("(%s)", strings.Join(returns, ", ")) - } + returnString := fmt.Sprintf("(%s)", strings.Join(returns, ", ")) + commentsString := "" if len(comments) > 0 { commentsString = strings.Join(comments, "\n") + "\n" @@ -131,6 +132,7 @@ func generateInterface(folder, outputFile, pkgName, structName, ifName, outputTe if err != nil { log.Panic(err) } + fmt.Println(out.String()) os.Remove(outputFile) formatted, err := imports.Process(outputFile, out.Bytes(), &imports.Options{Comments: true}) if err != nil {