Skip to content

Commit 4a51119

Browse files
committed
fix for named return parameters
1 parent f55c950 commit 4a51119

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
main
17+
.vscode/launch.json

main.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ func functionDef(fun *ast.FuncDecl, fset *token.FileSet) string {
6262
if err != nil {
6363
log.Fatalf("failed printing %s", err)
6464
}
65-
66-
returns = append(returns, typeNameBuf.String())
65+
if len(r.Names) > 0 {
66+
for _, k := range r.Names {
67+
returns = append(returns, fmt.Sprintf("%s %s", k.Name, typeNameBuf.String()))
68+
}
69+
} else {
70+
returns = append(returns, typeNameBuf.String())
71+
}
6772
}
6873
}
69-
returnString := ""
70-
if len(returns) == 1 {
71-
returnString = returns[0]
72-
} else if len(returns) > 1 {
73-
returnString = fmt.Sprintf("(%s)", strings.Join(returns, ", "))
74-
}
74+
returnString := fmt.Sprintf("(%s)", strings.Join(returns, ", "))
75+
7576
commentsString := ""
7677
if len(comments) > 0 {
7778
commentsString = strings.Join(comments, "\n") + "\n"
@@ -131,6 +132,7 @@ func generateInterface(folder, outputFile, pkgName, structName, ifName, outputTe
131132
if err != nil {
132133
log.Panic(err)
133134
}
135+
fmt.Println(out.String())
134136
os.Remove(outputFile)
135137
formatted, err := imports.Process(outputFile, out.Bytes(), &imports.Options{Comments: true})
136138
if err != nil {

0 commit comments

Comments
 (0)