Implement Run function for data server.
Co-authored-by: Hector Hurtado <hector.hurtado@bbva.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -22,3 +23,28 @@ func configRouter(rs []routeSpec) (r *mux.Router) {
|
||||
func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) })
|
||||
return r
|
||||
}
|
||||
|
||||
func Run(bindAddr string) {
|
||||
rs := []routeSpec{
|
||||
// request
|
||||
{"/handlers/{handlerID}/request/method", "GET", getRequestMethod},
|
||||
{"/handlers/{handlerID}/request/host", "GET", getRequestHost},
|
||||
{"/handlers/{handlerID}/request/path", "GET", getRequestPath},
|
||||
{"/handlers/{handlerID}/request/matches/{name}", "GET", getRequestMatches},
|
||||
{"/handlers/{handlerID}/request/params/{name}", "GET", getRequestParams},
|
||||
{"/handlers/{handlerID}/request/headers/{name}", "GET", getRequestHeaders},
|
||||
{"/handlers/{handlerID}/request/cookies/{name}", "GET", getRequestCookies},
|
||||
{"/handlers/{handlerID}/request/form/{name}", "GET", getRequestForm},
|
||||
{"/handlers/{handlerID}/request/files/{name}/filename", "GET", getRequestFileName},
|
||||
{"/handlers/{handlerID}/request/files/{name}/content", "GET", getRequestFileContent},
|
||||
{"/handlers/{handlerID}/request/body", "GET", getRequestBody},
|
||||
|
||||
// response
|
||||
{"/handlers/{handlerID}/response/status", "PUT", lockResponseWriter(setResponseStatus)},
|
||||
{"/handlers/{handlerID}/response/headers/name", "PUT", lockResponseWriter(setResponseHeaders)},
|
||||
{"/handlers/{handlerID}/response/cookies/name", "PUT", lockResponseWriter(setResponseCookies)},
|
||||
{"/handlers/{handlerID}/response/body", "PUT", lockResponseWriter(setResponseBody)},
|
||||
{"/handlers/{handlerID}/response/stream", "PUT", lockResponseWriter(setResponseBody)},
|
||||
}
|
||||
log.Fatal(http.ListenAndServe(bindAddr, configRouter(rs)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user