From 5cba9329c3d69a87b7cc872a46d5a8ab5886f435 Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Fri, 7 Apr 2017 08:59:24 +0200 Subject: [PATCH] Use constants for HTTP methods --- .travis.yml | 4 ++++ bucket-view_test.go | 2 +- buckets-view_test.go | 2 +- create-bucket_test.go | 2 +- delete-bucket_test.go | 2 +- delete-object_test.go | 2 +- get-object_test.go | 2 +- index-view_test.go | 2 +- main.go | 16 ++++++++-------- 9 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e50fcc1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: go + +go: + - 1.x diff --git a/bucket-view_test.go b/bucket-view_test.go index fc9b389..f738776 100644 --- a/bucket-view_test.go +++ b/bucket-view_test.go @@ -103,7 +103,7 @@ func TestBucketViewHandler(t *testing.T) { for _, tc := range tests { r := mux.NewRouter() r. - Methods("GET"). + Methods(http.MethodGet). Path("/buckets/{bucketName}"). Handler(BucketViewHandler(tc.s3)) diff --git a/buckets-view_test.go b/buckets-view_test.go index 459474d..6e3f626 100644 --- a/buckets-view_test.go +++ b/buckets-view_test.go @@ -42,7 +42,7 @@ func TestBucketsViewHandler(t *testing.T) { } for _, tc := range tests { - req, err := http.NewRequest("GET", "/buckets", nil) + req, err := http.NewRequest(http.MethodGet, "/buckets", nil) assert.NoError(err) rr := httptest.NewRecorder() diff --git a/create-bucket_test.go b/create-bucket_test.go index d7ef8db..aa1504d 100644 --- a/create-bucket_test.go +++ b/create-bucket_test.go @@ -48,7 +48,7 @@ func TestCreateBucketHandler(t *testing.T) { } for _, tc := range tests { - req, err := http.NewRequest("POST", "/api/buckets", bytes.NewBufferString(tc.body)) + req, err := http.NewRequest(http.MethodPost, "/api/buckets", bytes.NewBufferString(tc.body)) assert.NoError(err) rr := httptest.NewRecorder() diff --git a/delete-bucket_test.go b/delete-bucket_test.go index dc6a7b6..6e88260 100644 --- a/delete-bucket_test.go +++ b/delete-bucket_test.go @@ -32,7 +32,7 @@ func TestDeleteBucketHandler(t *testing.T) { } for _, tc := range tests { - req, err := http.NewRequest("DELETE", "/api/buckets/bucketName", nil) + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName", nil) assert.NoError(err) rr := httptest.NewRecorder() diff --git a/delete-object_test.go b/delete-object_test.go index ea79b75..9063fa3 100644 --- a/delete-object_test.go +++ b/delete-object_test.go @@ -32,7 +32,7 @@ func TestDeleteObjectHandler(t *testing.T) { } for _, tc := range tests { - req, err := http.NewRequest("DELETE", "/api/buckets/bucketName/objects/objectName", nil) + req, err := http.NewRequest(http.MethodDelete, "/api/buckets/bucketName/objects/objectName", nil) assert.NoError(err) rr := httptest.NewRecorder() diff --git a/get-object_test.go b/get-object_test.go index 1e468f2..5dd06ee 100644 --- a/get-object_test.go +++ b/get-object_test.go @@ -36,7 +36,7 @@ func TestGetObjectHandler(t *testing.T) { for _, tc := range tests { r := mux.NewRouter() r. - Methods("GET"). + Methods(http.MethodGet). Path("/buckets/{bucketName}/objects/{objectName}"). Handler(GetObjectHandler(tc.s3)) diff --git a/index-view_test.go b/index-view_test.go index 8394b08..b428209 100644 --- a/index-view_test.go +++ b/index-view_test.go @@ -22,7 +22,7 @@ func TestIndexViewHandler(t *testing.T) { } for _, tc := range tests { - req, err := http.NewRequest("GET", "/", nil) + req, err := http.NewRequest(http.MethodGet, "/", nil) assert.NoError(err) rr := httptest.NewRecorder() diff --git a/main.go b/main.go index c3ef265..1663f8f 100644 --- a/main.go +++ b/main.go @@ -16,21 +16,21 @@ func main() { router := mux.NewRouter() router. - Methods("GET"). + Methods(http.MethodGet). Path("/"). Handler(adapters.Adapt( IndexViewHandler(), logging.Handler(logger), )) router. - Methods("GET"). + Methods(http.MethodGet). Path("/buckets"). Handler(adapters.Adapt( BucketsViewHandler(s3), logging.Handler(logger), )) router. - Methods("GET"). + Methods(http.MethodGet). Path("/buckets/{bucketName}"). Handler(adapters.Adapt( BucketViewHandler(s3), @@ -41,35 +41,35 @@ func main() { br := api.PathPrefix("/buckets").Subrouter() br. - Methods("POST"). + Methods(http.MethodPost). Path(""). Handler(adapters.Adapt( CreateBucketHandler(s3), logging.Handler(logger), )) br. - Methods("DELETE"). + Methods(http.MethodDelete). Path("/{bucketName}"). Handler(adapters.Adapt( DeleteBucketHandler(s3), logging.Handler(logger), )) br. - Methods("POST"). + Methods(http.MethodPost). Path("/{bucketName}/objects"). Handler(adapters.Adapt( CreateObjectHandler(s3), logging.Handler(logger), )) br. - Methods("GET"). + Methods(http.MethodGet). Path("/{bucketName}/objects/{objectName}"). Handler(adapters.Adapt( GetObjectHandler(s3), logging.Handler(logger), )) br. - Methods("DELETE"). + Methods(http.MethodDelete). Path("/{bucketName}/objects/{objectName}"). Handler(adapters.Adapt( DeleteObjectHandler(s3),