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
Other
530 stars 55 forks source link

Does not understand returning duple from Map #37

Closed andycook-bcs closed 7 years ago

andycook-bcs commented 7 years ago

I'm trying to return the duple from getting the value in a map, but goreturns is breaking the code.

Orignal/Expected:

func (r *Request) GetHeader(key string) (string, bool) {
    if r.Headers == nil {
        return "", false
    }
    return r.Headers[key]
}

After:

func (r *Request) GetHeader(key string) (string, bool) {
    if r.Headers == nil {
        return "", false
    }
    return "", r.Headers[key]
}

Workaround

func (r *Request) GetHeader(key string) (string, bool) {
    if r.Headers == nil {
        return "", false
    }
        value, ok :=  r.Headers[key]
    return value, ok
}
andycook-bcs commented 7 years ago

Nope that code doesn't work any way!