Implement configRouter

Co-authored-by: Hector Hurtado <hector.hurtado@bbva.com>
This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-22 09:48:58 +02:00
parent 5eae018ee6
commit 6a05b31320
2 changed files with 65 additions and 0 deletions
+23
View File
@@ -1 +1,24 @@
package data
import (
"net/http"
"github.com/gorilla/mux"
)
type routeSpec struct {
route string
method string
rh resourceHandler
}
func configRouter(rs []routeSpec) (r *mux.Router) {
r = mux.NewRouter()
for _, s := range rs {
r.HandleFunc(s.route, checkHandler(s.rh)).Methods(s.method)
}
r.HandleFunc(
"/handlers/{handlerID}/{resource:.*}",
func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) })
return r
}