Closed razonyang closed 7 years ago
@abbot just for explaining my thought, and thanks your reply. :)
info, ok := ctx.Value(infoKey).(*Info)
// If false was returned, info is nil, in my humble opinion,
// it is not necessary to check the result of assertion.
if !ok {
return nil
}
return info
I'm not sure what exactly is optimised this way? FWIW I'd prefer to keep context value check explicit. Also, naked returns are generally discouraged. See https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters