Remove route name
This commit is contained in:
parent
2ff5114186
commit
695ff278b6
3 changed files with 3 additions and 14 deletions
|
@ -7,17 +7,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger logs HTTP requests
|
// Logger logs HTTP requests
|
||||||
func Logger(inner http.Handler, name string) http.Handler {
|
func Logger(inner http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
inner.ServeHTTP(w, r)
|
inner.ServeHTTP(w, r)
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"%s\t%s\t%s\t%s",
|
"%s\t%s\t%s",
|
||||||
r.Method,
|
r.Method,
|
||||||
r.RequestURI,
|
r.RequestURI,
|
||||||
name,
|
|
||||||
time.Since(start),
|
time.Since(start),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,12 +14,11 @@ func NewRouter() *mux.Router {
|
||||||
var handler http.Handler
|
var handler http.Handler
|
||||||
|
|
||||||
handler = route.HandlerFunc
|
handler = route.HandlerFunc
|
||||||
handler = Logger(handler, route.Name)
|
handler = Logger(handler)
|
||||||
|
|
||||||
router.
|
router.
|
||||||
Methods(route.Method).
|
Methods(route.Method).
|
||||||
Path(route.Pattern).
|
Path(route.Pattern).
|
||||||
Name(route.Name).
|
|
||||||
Handler(handler)
|
Handler(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import "net/http"
|
||||||
|
|
||||||
// Route represents a path of the API
|
// Route represents a path of the API
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Name string
|
|
||||||
Method string
|
Method string
|
||||||
Pattern string
|
Pattern string
|
||||||
HandlerFunc http.HandlerFunc
|
HandlerFunc http.HandlerFunc
|
||||||
|
@ -15,49 +14,41 @@ type Routes []Route
|
||||||
|
|
||||||
var routes = Routes{
|
var routes = Routes{
|
||||||
Route{
|
Route{
|
||||||
"Redirect to /buckets",
|
|
||||||
"GET",
|
"GET",
|
||||||
"/",
|
"/",
|
||||||
indexPageHandler,
|
indexPageHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Load Buckets Page",
|
|
||||||
"GET",
|
"GET",
|
||||||
"/buckets",
|
"/buckets",
|
||||||
bucketsPageHandler,
|
bucketsPageHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Load Bucket Page",
|
|
||||||
"GET",
|
"GET",
|
||||||
"/buckets/{bucketName}",
|
"/buckets/{bucketName}",
|
||||||
bucketPageHandler,
|
bucketPageHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Create Bucket",
|
|
||||||
"POST",
|
"POST",
|
||||||
"/api/buckets",
|
"/api/buckets",
|
||||||
createBucketHandler,
|
createBucketHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Delete Bucket",
|
|
||||||
"DELETE",
|
"DELETE",
|
||||||
"/api/buckets/{bucketName}",
|
"/api/buckets/{bucketName}",
|
||||||
deleteBucketHandler,
|
deleteBucketHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Download Object",
|
|
||||||
"GET",
|
"GET",
|
||||||
"/api/buckets/{bucketName}/objects/{objectName}",
|
"/api/buckets/{bucketName}/objects/{objectName}",
|
||||||
getObjectHandler,
|
getObjectHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Upload Object",
|
|
||||||
"POST",
|
"POST",
|
||||||
"/api/buckets/{bucketName}/objects",
|
"/api/buckets/{bucketName}/objects",
|
||||||
createObjectHandler,
|
createObjectHandler,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"Delete Object",
|
|
||||||
"DELETE",
|
"DELETE",
|
||||||
"/api/buckets/{bucketName}/objects/{objectName}",
|
"/api/buckets/{bucketName}/objects/{objectName}",
|
||||||
deleteObjectHandler,
|
deleteObjectHandler,
|
||||||
|
|
Loading…
Reference in a new issue