Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sqs/goreturns
A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types
https://github.com/sqs/goreturns
Last synced: 4 days ago
JSON representation
A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types
- Host: GitHub
- URL: https://github.com/sqs/goreturns
- Owner: sqs
- License: other
- Created: 2014-10-07T15:48:08.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-10-30T19:15:05.000Z (about 1 year ago)
- Last Synced: 2024-11-28T17:42:39.572Z (14 days ago)
- Language: Go
- Size: 6.69 MB
- Stars: 531
- Watchers: 10
- Forks: 55
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - sqs/goreturns - A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types (Go)
- awesome-go-extra - goreturns - like tool for Go programmers that fills in Go return statements with zero values to match the func return types|513|57|29|2014-10-07T15:48:08Z|2020-10-17T19:35:15Z| (Code Analysis / Routers)
- trackawesomelist - goreturns (⭐529) - Adds zero-value return statements to match the func return types. (Recently Updated / [Sep 15, 2024](/content/2024/09/15/README.md))
README
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](screencast.gif)
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.