validation of routes

This commit is contained in:
César Gallego Rodríguez
2019-10-10 09:44:41 +02:00
parent d0764f07a4
commit b82b0d2ef1
2 changed files with 48 additions and 42 deletions
+11 -3
View File
@@ -12,18 +12,22 @@ import (
"github.com/BBVA/kapow/internal/server/user"
)
// Run must start the control server in a specific address
func Run(bindAddr string) {
r := configRouter()
log.Fatal(http.ListenAndServe(bindAddr, r))
}
func configRouter() *mux.Router {
r := mux.NewRouter()
r.HandleFunc("/routes/{id}", removeRoute).
Methods("DELETE")
r.HandleFunc("/routes", listRoutes).
Methods("GET")
r.HandleFunc("/routes", addRoute).
Methods("POST")
log.Fatal(http.ListenAndServe(bindAddr, r))
return r
}
// user.Routes.Remove() []model.Route
@@ -67,6 +71,10 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusUnprocessableEntity)
return
}
if route.Pattern == "" {
res.WriteHeader(http.StatusUnprocessableEntity)
return
}
created := funcAdd(route)
createdBytes, _ := json.Marshal(created)