Skip to content

Commit

Permalink
Merge pull request #48 from vsvastey/usr/vsvastey/redirect
Browse files Browse the repository at this point in the history
feat: add check status code in http.Redirect
  • Loading branch information
sashamelentyev committed Aug 15, 2022
2 parents 8ac2a02 + 27b9021 commit 7c6dfe6
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
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
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 7c6dfe6

Please sign in to comment.