Skip to content

Commit

Permalink
chore: Return early and skip unnecessary returns
Browse files Browse the repository at this point in the history
Thanks golangci-lint, I guess I should install something like you
locally.
  • Loading branch information
chelmertz committed Sep 25, 2024
1 parent 6db32c6 commit c3c2b8d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,25 @@ func ServeWeb(url, username string, goldenTestingEnabled bool, store *storage.St

action := r.PathValue("action")

if action == "bury" || action == "unbury" {
var buryFunc func(string) error
if action == "bury" {
buryFunc = store.Bury
} else {
buryFunc = store.Unbury
}

if err := buryFunc(ghPrUrl); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(fmt.Sprintf("couldn't toggle bury for PR %s", ghPrUrl)))
return
}

w.WriteHeader(http.StatusNoContent)
return
} else {
var buryFunc func(string) error
switch action {
case "bury":
buryFunc = store.Bury
case "unbury":
buryFunc = store.Unbury
default:
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(fmt.Sprintf("action '%s' is not supported", action)))
return
}

if err := buryFunc(ghPrUrl); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(fmt.Sprintf("couldn't toggle bury for PR %s", ghPrUrl)))
return
}

w.WriteHeader(http.StatusNoContent)
})

// Let's say that v0 represents "may change at any time", read the code.
Expand Down

0 comments on commit c3c2b8d

Please sign in to comment.