I want to bind 2 urls to 1 function, like below.
router.HandleFunc("/_Users", controller.AddResource)
router.HandleFunc("/Resources/{resourceName}", controller.AddResource)
the "controller.AddResource" is a global function. the code like below:
function AddResource(req *http.Request, w http.ResponseWriter){
vars := mux.Vars(req)
resourceName := vars["resourceName"]
data = request.Body
AddDataToResource(resourceName, data)
}
so how can I set the vars(resourceName='_User') in the first router?
Create a handler wrapper that sets the mux var:
Wrap the user controller:
A simpler option is to write an AddUser function that calls through to the generic controller:
Perhaps even simpler is to check for "" in the handler: