r and w in ResponseWriter and Request Golang

huangapple go评论80阅读模式
英文:

r and w in ResponseWriter and Request Golang

问题

这是一个有点傻的问题,但我想问一下,在w http.ResponseWriter, r *http.Request中,我可以使用任何名称代替rw吗?还是必须始终使用rw

谢谢。

英文:

This is a bit a silly question but I wanted to ask that can I use any name instead of r and w in the w http.ResponseWriter, r *http.Request or should it be r and w always?

Thanks

答案1

得分: 1

不管参数的名称是什么,你只需要遵守函数签名即可。

func (firstParameter http.ResponseWriter, secondParameter http.ResponseWriter)
英文:

It doesn't matter the name of the parameter, you just need to obey the function signature

func (firstParameter http.ResponseWriter, secondParameter http.ResponseWriter)

答案2

得分: 0

我相信你的问题是,使用rw是否符合惯用法。我认为不符合。只要你给参数起合理的名称(即不影响可读性),就可以了。

英文:

I believe what you asking is, is it idomatic to use r and w. I don’t think it is. So long as you give the parameters reasonable names (i.e. they don’t hinder readability) you are fine.

huangapple
  • 本文由 发表于 2022年3月5日 20:10:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/71362063.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定