Skip to content

Commit 40aae56

Browse files
Merge pull request #49 from sashamelentyev/feat/redirect-handler
feat: add check status code in http.RedirectHandler
2 parents 7c6dfe6 + 407243e commit 40aae56

File tree

3 files changed

+517
-0
lines changed

3 files changed

+517
-0
lines changed

pkg/analyzer/analyzer.go

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
116116
if basicLit := getBasicLitFromArgs(n.Args, 4, 3, token.INT); basicLit != nil {
117117
checkHTTPStatusCode(pass, basicLit)
118118
}
119+
120+
case "RedirectHandler":
121+
if !lookupFlag(pass, HTTPStatusCodeFlag) {
122+
return
123+
}
124+
125+
if basicLit := getBasicLitFromArgs(n.Args, 2, 1, token.INT); basicLit != nil {
126+
checkHTTPStatusCode(pass, basicLit)
127+
}
119128
}
120129
default:
121130
if selectorExpr.Sel.Name == "WriteHeader" {

pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@ func _() {
114114
http.Redirect(w, r, "", {{ $value }})
115115
}
116116
{{ end -}}
117+
118+
{{ range $key, $value := .Mapping }}
119+
func _() {
120+
http.RedirectHandler("", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
121+
}
122+
{{ end -}}
123+
124+
{{ range $key, $value := .Mapping }}
125+
func _() {
126+
http.RedirectHandler("", {{ $value }})
127+
}
128+
{{ end -}}

0 commit comments

Comments
 (0)