code: func CORSMethodMiddleware(r *Router) MiddlewareFunc {
  	return func(next http.Handler) http.Handler {
  		return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
  			var allMethods []string
  
  			err := r.Walk(func(route *Route, _ *Router, _ []*Route) error {
  				for _, m := range route.matchers {
  					if _, ok := m.(*routeRegexp); ok {
  						if m.Match(req, &RouteMatch{}) {
  							methods, err := route.GetMethods()
  							if err != nil {
  								return err
  							}
  
  							allMethods = append(allMethods, methods...)
  						}
  						break
  					}
  				}
  				return nil
  			})
  
  			if err == nil {
  				w.Header().Set("Access-Control-Allow-Methods", strings.Join(append(allMethods, "OPTIONS"), ","))
  
  				if req.Method == "OPTIONS" {
  					return
  				}
  			}
  
  			next.ServeHTTP(w, req)
  		})
  	}
  }
docs: // CORSMethodMiddleware sets the Access-Control-Allow-Methods response header
  // on a request, by matching routes based only on paths. It also handles
  // OPTIONS requests, by settings Access-Control-Allow-Methods, and then
  // returning without calling the next http handler.