Skip to content
A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types
Branch: master
Clone or download
Latest commit 538ac60 Oct 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_samples Remove bare returns (#24) Aug 25, 2016
returns Use pkgDir variable Oct 28, 2018
.travis.yml fix travis go version Mar 2, 2018
LICENSE basic returns rewriting Oct 7, 2014
README.md use github.com import path for simplicity Mar 2, 2018
goreturns.go fix typo Mar 2, 2018
screencast.gif screencast partially shown in a gif. Mar 30, 2016

README.md

This tool adds zero-value return values to incomplete Go return statements, to save you time when writing Go. It is inspired by and based on goimports.

short screencast

full 30-second screencast: http://youtu.be/hyEMO9vtKZ8

For example, the following incomplete return statement:

func F() (*MyType, int, error) { return errors.New("foo") }

is made complete by adding nil and 0 returns (the zero values for *MyType and int):

func F() (*MyType, int, error) { return nil, 0, errors.New("foo") }

To install:

go get -u github.com/sqs/goreturns

To run:

goreturns file.go

To view a diff showing what it'd do on a sample file:

goreturns -d $GOPATH/github.com/sqs/goreturns/_sample/a.go

Editor integration: replace gofmt or goimports in your post-save hook with goreturns. By default goreturns calls goimports on files before performing its own processing.

It acts the same as gofmt (same flags, etc) but in addition to code formatting, also fixes returns.

You can’t perform that action at this time.