Implement accessLog handler

This commit is contained in:
Harshavardhana
2015-10-19 12:15:19 -07:00
parent e9d5ec3d64
commit b9ea18b8b8
5 changed files with 140 additions and 6 deletions
+11 -6
View File
@@ -23,6 +23,13 @@ import (
"github.com/minio/minio/pkg/fs"
)
// CloudStorageAPI container for API and also carries OP (operation) channel
type CloudStorageAPI struct {
Filesystem fs.Filesystem
Anonymous bool // do not checking for incoming signatures, allow all requests
AccessLog bool // if true log all incoming request
}
// registerCloudStorageAPI - register all the handlers to their respective paths
func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
mux.HandleFunc("/", a.ListBucketsHandler).Methods("GET")
@@ -46,12 +53,6 @@ func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
mux.HandleFunc("/{bucket}/{object:.*}", a.DeleteObjectHandler).Methods("DELETE")
}
// CloudStorageAPI container for API and also carries OP (operation) channel
type CloudStorageAPI struct {
Filesystem fs.Filesystem
Anonymous bool // do not checking for incoming signatures, allow all requests
}
// getNewCloudStorageAPI instantiate a new CloudStorageAPI
func getNewCloudStorageAPI(conf serverConfig) CloudStorageAPI {
fs, err := fs.New()
@@ -65,6 +66,7 @@ func getNewCloudStorageAPI(conf serverConfig) CloudStorageAPI {
return CloudStorageAPI{
Filesystem: fs,
Anonymous: conf.Anonymous,
AccessLog: conf.AccessLog,
}
}
@@ -77,6 +79,9 @@ func getCloudStorageAPIHandler(api CloudStorageAPI) http.Handler {
if !api.Anonymous {
mwHandlers = append(mwHandlers, SignatureHandler)
}
if api.AccessLog {
mwHandlers = append(mwHandlers, AccessLogHandler)
}
mux := router.NewRouter()
registerCloudStorageAPI(mux, api)
return registerCustomMiddleware(mux, mwHandlers...)