Skip to content

Commit

Permalink
fix for named return parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
reflog committed Apr 8, 2020
1 parent f55c950 commit 4a51119
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/
main
.vscode/launch.json
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4a51119

Please sign in to comment.