du4373 2018-10-15 00:47
浏览 121

我应该避免在生产代码中使用net / http / httptest吗?

I like the ability to present a buffered net/http.ResponseWriter as a net/http.Response in some situations which net/http/httptest.ResponseRecorder would give me, but the package name makes me a bit concerned about using it in production code. I understand that it’s intended to be used primarily for testing, but am unsure if I am asking for trouble using it in production code.

Am I tempting fate?

  • 写回答

1条回答 默认 最新

  • dorflv5944 2018-10-15 06:00
    关注

    You should not use this code in production. No matter what you are attempting to achieve.

    httptest.ResponseRecorder's ultimate purpose is to facilitate testing, and will thus always be extended, optimized—rewritten—with testing in mind. Any assumption can be made in this package, as long as it makes the package better at testing. The package authors intended for this to be "used in concert with go test"¹. I interpret that as discouraging production use, because they are then free to break e.g. your production usage in favor of go test usage.

    Another argument is that of security. The security model of any test package is going to be that the usage is trusted, whereas non-testing code will be the opposite.

    The world of software a perilous place. You are asking to make it even more perilous.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值