Use constants for HTTP methods

This commit is contained in:
Lena Fuhrimann 2017-04-07 08:59:24 +02:00
parent a1bd061b98
commit 5cba9329c3
9 changed files with 19 additions and 15 deletions

4
.travis.yml Normal file
View file

@ -0,0 +1,4 @@
language: go
go:
- 1.x

View file

@ -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))

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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))

View file

@ -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()

16
main.go
View file

@ -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),