mediaapi/routing: Use common.MakeAPI

main
Robert Swain 2017-05-26 13:37:07 +02:00
parent 2fa0ae29d7
commit e8d3b4648b
1 changed files with 2 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import (
"sync" "sync"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/mediaapi/config" "github.com/matrix-org/dendrite/mediaapi/config"
"github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/dendrite/mediaapi/types"
"github.com/matrix-org/dendrite/mediaapi/writers" "github.com/matrix-org/dendrite/mediaapi/writers"
@ -34,7 +35,7 @@ const pathPrefixR0 = "/_matrix/media/v1"
func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg *config.MediaAPI) { func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg *config.MediaAPI) {
apiMux := mux.NewRouter() apiMux := mux.NewRouter()
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
r0mux.Handle("/upload", makeAPI("upload", func(req *http.Request) util.JSONResponse { r0mux.Handle("/upload", common.MakeAPI("upload", func(req *http.Request) util.JSONResponse {
return writers.Upload(req, cfg) return writers.Upload(req, cfg)
})) }))
@ -58,9 +59,3 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg *config.MediaAPI
servMux.Handle("/metrics", prometheus.Handler()) servMux.Handle("/metrics", prometheus.Handler())
servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) servMux.Handle("/api/", http.StripPrefix("/api", apiMux))
} }
// make a util.JSONRequestHandler function into an http.Handler.
func makeAPI(metricsName string, f func(*http.Request) util.JSONResponse) http.Handler {
h := util.NewJSONRequestHandler(f)
return prometheus.InstrumentHandler(metricsName, util.MakeJSONAPI(h))
}