Skip to content

Commit

Permalink
Precompute JSON body for version
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Apr 10, 2022
1 parent 6457764 commit ca03a50
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func BasicAuthMiddleware(next http.Handler, username, password, realm string) ht

// VersionHandler returns a simple JSON response from a version string.
func VersionHandler(version string) http.HandlerFunc {
bodyBytes := []byte(`{"version":"` + version + `"}`)
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"version":"` + version + `"}`))
w.Write(bodyBytes)
}
}

Expand Down

0 comments on commit ca03a50

Please sign in to comment.