Attach logger to main mux

This commit is contained in:
Lena Fuhrimann 2017-09-19 19:00:57 +02:00
parent 9e48031767
commit 8280120d9e

View file

@ -42,75 +42,51 @@ func main() {
} }
// Set up logger // Set up logger
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime) l := log.New(os.Stdout, "", log.Ldate|log.Ltime)
// Set up router // Set up router
r := mux.NewRouter().StrictSlash(true) r := mux.NewRouter().StrictSlash(true)
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/"). Path("/").
Handler(adapters.Adapt( Handler(http.RedirectHandler("/buckets", http.StatusPermanentRedirect))
http.RedirectHandler("/buckets", http.StatusPermanentRedirect),
logging.Handler(logger),
))
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/buckets"). Path("/buckets").
Handler(adapters.Adapt( Handler(s3manager.BucketsViewHandler(s3))
s3manager.BucketsViewHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/buckets/{bucketName}"). Path("/buckets/{bucketName}").
Handler(adapters.Adapt( Handler(s3manager.BucketViewHandler(s3))
s3manager.BucketViewHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodPost). Methods(http.MethodPost).
Path("/api/buckets"). Path("/api/buckets").
Handler(adapters.Adapt( Handler(s3manager.CreateBucketHandler(s3))
s3manager.CreateBucketHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodDelete). Methods(http.MethodDelete).
Path("/api/buckets/{bucketName}"). Path("/api/buckets/{bucketName}").
Handler(adapters.Adapt( Handler(s3manager.DeleteBucketHandler(s3))
s3manager.DeleteBucketHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodPost). Methods(http.MethodPost).
Headers(s3manager.HeaderContentType, s3manager.ContentTypeJSON). Headers(s3manager.HeaderContentType, s3manager.ContentTypeJSON).
Path("/api/buckets/{bucketName}/objects"). Path("/api/buckets/{bucketName}/objects").
Handler(adapters.Adapt( Handler(s3manager.CopyObjectHandler(s3))
s3manager.CopyObjectHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodPost). Methods(http.MethodPost).
HeadersRegexp(s3manager.HeaderContentType, s3manager.ContentTypeMultipartForm). HeadersRegexp(s3manager.HeaderContentType, s3manager.ContentTypeMultipartForm).
Path("/api/buckets/{bucketName}/objects"). Path("/api/buckets/{bucketName}/objects").
Handler(adapters.Adapt( Handler(s3manager.CreateObjectHandler(s3))
s3manager.CreateObjectHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodGet). Methods(http.MethodGet).
Path("/api/buckets/{bucketName}/objects/{objectName}"). Path("/api/buckets/{bucketName}/objects/{objectName}").
Handler(adapters.Adapt( Handler(s3manager.GetObjectHandler(s3))
s3manager.GetObjectHandler(s3),
logging.Handler(logger),
))
r. r.
Methods(http.MethodDelete). Methods(http.MethodDelete).
Path("/api/buckets/{bucketName}/objects/{objectName}"). Path("/api/buckets/{bucketName}/objects/{objectName}").
Handler(adapters.Adapt( Handler(s3manager.DeleteObjectHandler(s3))
s3manager.DeleteObjectHandler(s3),
logging.Handler(logger),
))
log.Fatal(http.ListenAndServe(":"+*port, r)) log.Fatal(http.ListenAndServe(":"+*port, adapters.Adapt(
r,
logging.Handler(l),
)))
} }