Skip to content

Commit

Permalink
Change RegisterWithAuth methods
Browse files Browse the repository at this point in the history
  • Loading branch information
levichevdmitry committed Dec 2, 2020
1 parent 3d3d2c7 commit 5ca1f3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions services/HttpEndpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/gorilla/mux"
cconf "github.com/pip-services3-go/pip-services3-commons-go/config"
cdata "github.com/pip-services3-go/pip-services3-commons-go/data"
crefer "github.com/pip-services3-go/pip-services3-commons-go/refer"
cvalid "github.com/pip-services3-go/pip-services3-commons-go/validate"
ccount "github.com/pip-services3-go/pip-services3-components-go/count"
Expand Down Expand Up @@ -378,13 +377,13 @@ func (c *HttpEndpoint) RegisterRoute(method string, route string, schema *cvalid
// - authorize the authorization interceptor
// - action the action to perform at the given route.
func (c *HttpEndpoint) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema,
authorize func(w http.ResponseWriter, r *http.Request, user *cdata.AnyValueMap, next http.HandlerFunc),
authorize func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc),
action http.HandlerFunc) {

if authorize != nil {
nextAction := action
action = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
authorize(w, r, nil, nextAction)
authorize(w, r, nextAction)
})
}

Expand Down
6 changes: 3 additions & 3 deletions services/RestService.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,17 @@ func (c *RestService) RegisterRoute(method string, route string, schema *cvalid.
// - authorize an authorization interceptor
// - action an action function that is called when operation is invoked.
func (c *RestService) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema,
authorize func(res http.ResponseWriter, req *http.Request, user *cdata.AnyValueMap, next http.HandlerFunc),
authorize func(res http.ResponseWriter, req *http.Request, next http.HandlerFunc),
action func(res http.ResponseWriter, req *http.Request)) {
if c.Endpoint == nil {
return
}
route = c.appendBaseRoute(route)
c.Endpoint.RegisterRouteWithAuth(
method, route, schema,
func(res http.ResponseWriter, req *http.Request, user *cdata.AnyValueMap, next http.HandlerFunc) {
func(res http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
if authorize != nil {
authorize(res, req, user, next)
authorize(res, req, next)
} else {
next.ServeHTTP(res, req)
}
Expand Down

0 comments on commit 5ca1f3e

Please sign in to comment.