Chore: replace macaron with web package (#40136)
* replace macaron with web package * add web.go
This commit is contained in:
@@ -5,15 +5,14 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gopkg.in/macaron.v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
func Middleware(ac accesscontrol.AccessControl) func(macaron.Handler, accesscontrol.Evaluator) macaron.Handler {
|
||||
return func(fallback macaron.Handler, evaluator accesscontrol.Evaluator) macaron.Handler {
|
||||
func Middleware(ac accesscontrol.AccessControl) func(web.Handler, accesscontrol.Evaluator) web.Handler {
|
||||
return func(fallback web.Handler, evaluator accesscontrol.Evaluator) web.Handler {
|
||||
if ac.IsDisabled() {
|
||||
return fallback
|
||||
}
|
||||
@@ -73,6 +72,6 @@ func newID() string {
|
||||
func buildScopeParams(c *models.ReqContext) accesscontrol.ScopeParams {
|
||||
return accesscontrol.ScopeParams{
|
||||
OrgID: c.OrgId,
|
||||
URLParams: macaron.Params(c.Req),
|
||||
URLParams: web.Params(c.Req),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/macaron.v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
@@ -58,8 +57,8 @@ func TestMiddleware(t *testing.T) {
|
||||
fallbackCalled = true
|
||||
}
|
||||
|
||||
server := macaron.New()
|
||||
server.UseMiddleware(macaron.Renderer("../../public/views", "[[", "]]"))
|
||||
server := web.New()
|
||||
server.UseMiddleware(web.Renderer("../../public/views", "[[", "]]"))
|
||||
|
||||
server.Use(contextProvider())
|
||||
server.Use(Middleware(test.ac)(fallback, test.evaluator))
|
||||
@@ -81,8 +80,8 @@ func TestMiddleware(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func contextProvider() macaron.Handler {
|
||||
return func(c *macaron.Context) {
|
||||
func contextProvider() web.Handler {
|
||||
return func(c *web.Context) {
|
||||
reqCtx := &models.ReqContext{
|
||||
Context: c,
|
||||
Logger: log.New(""),
|
||||
|
||||
Reference in New Issue
Block a user