mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 22:56:41 +00:00
[NOD-319] Add query params to api server route handler (#394)
This commit is contained in:
parent
ae25ec2e6b
commit
db6d6293c7
@ -14,10 +14,10 @@ const (
|
|||||||
routeParamTxHash = "txHash"
|
routeParamTxHash = "txHash"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeHandler(handler func(vars map[string]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError)) func(http.ResponseWriter, *http.Request) {
|
func makeHandler(handler func(routeParams map[string]string, queryParams map[string][]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError)) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := utils.ToAPIServerContext(r.Context())
|
ctx := utils.ToAPIServerContext(r.Context())
|
||||||
response, hErr := handler(mux.Vars(r), ctx)
|
response, hErr := handler(mux.Vars(r), r.URL.Query(), ctx)
|
||||||
if hErr != nil {
|
if hErr != nil {
|
||||||
sendErr(ctx, w, hErr)
|
sendErr(ctx, w, hErr)
|
||||||
return
|
return
|
||||||
@ -44,7 +44,7 @@ func sendJSONResponse(w http.ResponseWriter, response interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainHandler(_ map[string]string, _ *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
func mainHandler(_ map[string]string, _ map[string][]string, _ *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
||||||
return "API server is running", nil
|
return "API server is running", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,15 +53,15 @@ func addRoutes(router *mux.Router) {
|
|||||||
|
|
||||||
router.HandleFunc(
|
router.HandleFunc(
|
||||||
fmt.Sprintf("/transaction/id/{%s}", routeParamTxID),
|
fmt.Sprintf("/transaction/id/{%s}", routeParamTxID),
|
||||||
makeHandler(func(vars map[string]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
makeHandler(func(routeParams map[string]string, queryParams map[string][]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
||||||
return controllers.GetTransactionByIDHandler(vars[routeParamTxID])
|
return controllers.GetTransactionByIDHandler(routeParams[routeParamTxID])
|
||||||
})).
|
})).
|
||||||
Methods("GET")
|
Methods("GET")
|
||||||
|
|
||||||
router.HandleFunc(
|
router.HandleFunc(
|
||||||
fmt.Sprintf("/transaction/hash/{%s}", routeParamTxHash),
|
fmt.Sprintf("/transaction/hash/{%s}", routeParamTxHash),
|
||||||
makeHandler(func(vars map[string]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
makeHandler(func(routeParams map[string]string, queryParams map[string][]string, ctx *utils.APIServerContext) (interface{}, *utils.HandlerError) {
|
||||||
return controllers.GetTransactionByHashHandler(vars[routeParamTxHash])
|
return controllers.GetTransactionByHashHandler(routeParams[routeParamTxHash])
|
||||||
})).
|
})).
|
||||||
Methods("GET")
|
Methods("GET")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user