Skip to content

Commit

Permalink
feat: add check status code in http.Redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
vsvastey authored and Vladimir Sokolov committed Aug 15, 2022
1 parent 8ac2a02 commit 27b9021
Show file tree
Hide file tree
Showing 3 changed files with 769 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func run(pass *analysis.Pass) (interface{}, error) {
if basicLit := getBasicLitFromArgs(n.Args, 1, 0, token.INT); basicLit != nil {
checkHTTPStatusCode(pass, basicLit)
}

case "Redirect":
if !lookupFlag(pass, HTTPStatusCodeFlag) {
return
}

if basicLit := getBasicLitFromArgs(n.Args, 4, 3, token.INT); basicLit != nil {
checkHTTPStatusCode(pass, basicLit)
}
}
default:
if selectorExpr.Sel.Name == "WriteHeader" {
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,19 @@ func _() {
http.StatusText({{ $value }})
}
{{ end -}}

{{ range $key, $value := .Mapping }}
func _() {
var w http.ResponseWriter
var r *http.Request
http.Redirect(w, r, "", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
}
{{ end -}}

{{ range $key, $value := .Mapping }}
func _() {
var w http.ResponseWriter
var r *http.Request
http.Redirect(w, r, "", {{ $value }})
}
{{ end -}}

0 comments on commit 27b9021

Please sign in to comment.