mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type Router interface {
|
type Router interface {
|
||||||
Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route
|
Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route
|
||||||
|
Get(pattern string, handlers ...macaron.Handler) *macaron.Route
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouteRegister interface {
|
type RouteRegister interface {
|
||||||
@@ -62,7 +63,14 @@ func (rr *routeRegister) Group(pattern string, fn func(rr RouteRegister), handle
|
|||||||
|
|
||||||
func (rr *routeRegister) Register(router Router) *macaron.Router {
|
func (rr *routeRegister) Register(router Router) *macaron.Router {
|
||||||
for _, r := range rr.routes {
|
for _, r := range rr.routes {
|
||||||
router.Handle(r.method, r.pattern, r.handlers)
|
// GET requests have to be added to macaron routing using Get()
|
||||||
|
// Otherwise HEAD requests will not be allowed.
|
||||||
|
// https://github.com/go-macaron/macaron/blob/a325110f8b392bce3e5cdeb8c44bf98078ada3be/router.go#L198
|
||||||
|
if r.method == http.MethodGet {
|
||||||
|
router.Get(r.pattern, r.handlers...)
|
||||||
|
} else {
|
||||||
|
router.Handle(r.method, r.pattern, r.handlers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, g := range rr.groups {
|
for _, g := range rr.groups {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -21,6 +22,16 @@ func (fr *fakeRouter) Handle(method, pattern string, handlers []macaron.Handler)
|
|||||||
return &macaron.Route{}
|
return &macaron.Route{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fr *fakeRouter) Get(pattern string, handlers ...macaron.Handler) *macaron.Route {
|
||||||
|
fr.route = append(fr.route, route{
|
||||||
|
pattern: pattern,
|
||||||
|
method: http.MethodGet,
|
||||||
|
handlers: handlers,
|
||||||
|
})
|
||||||
|
|
||||||
|
return &macaron.Route{}
|
||||||
|
}
|
||||||
|
|
||||||
func emptyHandlers(n int) []macaron.Handler {
|
func emptyHandlers(n int) []macaron.Handler {
|
||||||
res := []macaron.Handler{}
|
res := []macaron.Handler{}
|
||||||
for i := 1; n >= i; i++ {
|
for i := 1; n >= i; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user