【发布时间】:2018-12-17 03:22:38
【问题描述】:
如果您在渲染语句后不写return,您将向客户端发送多个 HTTP 状态。我真的很想避免这种情况,因为它既可能有安全隐患,也可能只是......奇怪的行为。
例子:
if passwordNotCorrect {
w.WriteHeader(http.StatusUnauthorized)
render.JSON(w, r, nil)
return // If this is missing, we will return both 401 and 200.
}
w.WriteHeader(http.StatusOK)
render.JSON(w, r, nil)
return
是否有任何 linter 可以警告您这一点,以避免愚蠢的错误?
【问题讨论】:
-
afaik 没有 linting 选项。涵盖用例的适当测试应该会有所帮助
标签: go