Use http package consts for http methods

This commit replaces occurences of http method strings with the
corresponding consts from the http package.

*Note* UPDATE is not strictly speaking a valid method and as such isn't
part of the http package (should be a PUT or PATCH?)

Signed-off-by: John McCabe <john@johnmccabe.net>
This commit is contained in:
John McCabe
2018-03-21 14:05:55 +00:00
committed by Alex Ellis
parent 0c7e59fe8a
commit fac3345668
5 changed files with 30 additions and 30 deletions

View File

@ -11,7 +11,7 @@ type CORSHandler struct {
func (c CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// https://raw.githubusercontent.com/openfaas/store/master/store.json
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.Header().Set("Access-Control-Allow-Methods", "GET")
w.Header().Set("Access-Control-Allow-Methods", http.MethodGet)
w.Header().Set("Access-Control-Allow-Origin", c.AllowedHost)
(*c.Upstream).ServeHTTP(w, r)

View File

@ -94,15 +94,15 @@ func main() {
r.HandleFunc("/system/alert", faasHandlers.Alert)
r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", queryFunction).Methods("GET")
r.HandleFunc("/system/functions", listFunctions).Methods("GET")
r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods("POST")
r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods("DELETE")
r.HandleFunc("/system/functions", faasHandlers.UpdateFunction).Methods("PUT")
r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", queryFunction).Methods(http.MethodGet)
r.HandleFunc("/system/functions", listFunctions).Methods(http.MethodGet)
r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods(http.MethodPost)
r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods(http.MethodDelete)
r.HandleFunc("/system/functions", faasHandlers.UpdateFunction).Methods(http.MethodPut)
if faasHandlers.QueuedProxy != nil {
r.HandleFunc("/async-function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.QueuedProxy).Methods("POST")
r.HandleFunc("/async-function/{name:[-a-zA-Z_0-9]+}", faasHandlers.QueuedProxy).Methods("POST")
r.HandleFunc("/async-function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.QueuedProxy).Methods(http.MethodPost)
r.HandleFunc("/async-function/{name:[-a-zA-Z_0-9]+}", faasHandlers.QueuedProxy).Methods(http.MethodPost)
r.HandleFunc("/system/async-report", faasHandlers.AsyncReport)
}
@ -113,13 +113,13 @@ func main() {
allowedCORSHost := "raw.githubusercontent.com"
fsCORS := handlers.DecorateWithCORS(fs, allowedCORSHost)
r.PathPrefix("/ui/").Handler(http.StripPrefix("/ui", fsCORS)).Methods("GET")
r.PathPrefix("/ui/").Handler(http.StripPrefix("/ui", fsCORS)).Methods(http.MethodGet)
r.HandleFunc("/", faasHandlers.RoutelessProxy).Methods("POST")
r.HandleFunc("/", faasHandlers.RoutelessProxy).Methods(http.MethodPost)
metricsHandler := metrics.PrometheusHandler()
r.Handle("/metrics", metricsHandler)
r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods("GET")
r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods(http.MethodGet)
tcpPort := 8080

View File

@ -29,8 +29,8 @@ func Test_HeadersAdded(t *testing.T) {
}
actualMethods := rr.Header().Get("Access-Control-Allow-Methods")
if actualMethods != "GET" {
t.Errorf("Access-Control-Allow-Methods: want: %s got: %s", "GET", actualMethods)
if actualMethods != http.MethodGet {
t.Errorf("Access-Control-Allow-Methods: want: %s got: %s", http.MethodGet, actualMethods)
}
}