Proposal: Add named return into functions

Author: rafaelbrenoCreated May 12, 2021Updated Dec 9, 2021
Labelshelp-wantedpending-example

There's this thing that I found recently, about returning named values (variables), for example:

go
import (
	"fmt"
	"net/url"
	"path"
)

// Instead of
func URLGetFilename(rawURL string) (string, error) {
	parsedURL, err := url.Parse(rawURL)
	if err != nil {
		return rawURL, err
	}
	return path.Base(parsedURL.Path), nil
}


// It's possible to do
func URLGetFilename(rawURL string) (parsedURL string, err error) {
	obj, err := url.Parse(rawURL)
	if err != nil {
		return
	}
	parsedURL = path.Base(obj.Path)
	return
}

Just a silly example to demonstrate the existence of it.