go version)?$ go version go version go1.13.1 linux/amd64
yes
go env)?Ubuntu 16.04
go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="git.sysop.bigo.sg"
GONOSUMDB="git.sysop.bigo.sg"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE="git.sysop.bigo.sg"
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/dev_volumn/dis-grep/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build890909968=/tmp/go-build -gno-record-gcc-switches"
fake code is here:
func B() {
}
func A() {
return B()
}
I want this works ok
It failed
In fact, A and B all have no return values, sometimes, for example in http handler, I need to cancel function with a 400 or something else:
func handler(ctx ...) {
...
// something went wrong
ctx.StatusCode(400)
return
}
But I can not just use return ctx.StatusCode(400) end this function, this make my code not clean, so, may golang make return with no value legal when function itself has no return value too?
thanks!!!
if A has a return int, and B has a return int, direct return B() is ok, so NO return params maybe should be same with NO return params I think, so such code can we same
How is
ctx.StatusCode(400)
return
less clean than
return ctx.StatusCode(400)
? They are roughly the same thing... except allowing the second one in a function that returns nothing would be misleading.
I think the confusion that allowing this syntax would cause would far exceed the small benefit of not having to write ctx.StatusCode(400) and return on two different lines.
ok, thanks
For language change proposals, please fill out the template at https://go.googlesource.com/proposal/+/bd3ac287ccbebb2d12a386f1f1447876dd74b54d/go2-language-changes.md .
When you are done, please reply to the issue with @gopherbot please remove label WaitingForInfo.
Thanks!
Timed out in state WaitingForInfo. Closing.
(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)
Most helpful comment
How is
less clean than
? They are roughly the same thing... except allowing the second one in a function that returns nothing would be misleading.
I think the confusion that allowing this syntax would cause would far exceed the small benefit of not having to write
ctx.StatusCode(400)andreturnon two different lines.