Use constants for HTTP methods
This commit is contained in:
parent
a1bd061b98
commit
5cba9329c3
9 changed files with 19 additions and 15 deletions
4
.travis.yml
Normal file
4
.travis.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.x
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
16
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),
|
||||
|
|
Loading…
Reference in a new issue