Macaron cleanup (#37795)

* simplify some dependency injection in macaron
* remove unused internal server error handler from macaron
* remove internal server error handler from the router
* remove unused combo router api
* remove unused parts of the macaron router
This commit is contained in:
Serge Zaitsev
2021-08-30 11:48:34 +02:00
committed by GitHub
parent 74afe809af
commit d15cbe4b4e
9 changed files with 38 additions and 235 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ func (hs *HTTPServer) initAppPluginRoutes(r *macaron.Macaron) {
}
}
handlers = append(handlers, AppPluginRoute(route, plugin.Id, hs))
r.Route(url, route.Method, handlers...)
r.Handle(route.Method, url, handlers)
log.Debugf("Plugins: Adding proxy route %s", url)
}
}
-2
View File
@@ -136,8 +136,6 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
socialService social.Service, oauthTokenService oauthtoken.OAuthTokenService) (*HTTPServer, error) {
macaron.Env = cfg.Env
m := macaron.New()
// automatically set HEAD for every GET
m.SetAutoHead(true)
hs := &HTTPServer{
Cfg: cfg,
+2 -2
View File
@@ -10,8 +10,8 @@ import (
)
type Router interface {
Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route
Get(pattern string, handlers ...macaron.Handler) *macaron.Route
Handle(method, pattern string, handlers []macaron.Handler)
Get(pattern string, handlers ...macaron.Handler)
}
// RouteRegister allows you to add routes and macaron.Handlers
+2 -6
View File
@@ -12,24 +12,20 @@ type fakeRouter struct {
route []route
}
func (fr *fakeRouter) Handle(method, pattern string, handlers []macaron.Handler) *macaron.Route {
func (fr *fakeRouter) Handle(method, pattern string, handlers []macaron.Handler) {
fr.route = append(fr.route, route{
pattern: pattern,
method: method,
handlers: handlers,
})
return &macaron.Route{}
}
func (fr *fakeRouter) Get(pattern string, handlers ...macaron.Handler) *macaron.Route {
func (fr *fakeRouter) Get(pattern string, handlers ...macaron.Handler) {
fr.route = append(fr.route, route{
pattern: pattern,
method: http.MethodGet,
handlers: handlers,
})
return &macaron.Route{}
}
func emptyHandlers(n int) []macaron.Handler {
+8 -7
View File
@@ -17,7 +17,6 @@ package httpstatic
import (
"fmt"
"log"
"net/http"
"os"
"path"
@@ -26,6 +25,7 @@ import (
"strings"
"sync"
"github.com/grafana/grafana/pkg/infra/log"
"gopkg.in/macaron.v1"
)
@@ -115,7 +115,7 @@ func prepareStaticOptions(dir string, options []StaticOptions) StaticOptions {
return prepareStaticOption(dir, opt)
}
func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) bool {
func staticHandler(ctx *macaron.Context, log log.Logger, opt StaticOptions) bool {
if ctx.Req.Method != "GET" && ctx.Req.Method != "HEAD" {
return false
}
@@ -138,7 +138,7 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
}
defer func() {
if err := f.Close(); err != nil {
log.Printf("Failed to close file: %s\n", err)
log.Error("Failed to close file", "error", err)
}
}()
@@ -171,7 +171,7 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
}
defer func() {
if err := indexFile.Close(); err != nil {
log.Printf("Failed to close file: %s", err)
log.Error("Failed to close file", "error", err)
}
}()
@@ -182,7 +182,7 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
}
if !opt.SkipLogging {
log.Printf("[Static] Serving %s\n", file)
log.Info("[Static] Serving", "file", file)
}
// Add an Expires header to the static content
@@ -198,7 +198,8 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
func Static(directory string, staticOpt ...StaticOptions) macaron.Handler {
opt := prepareStaticOptions(directory, staticOpt)
return func(ctx *macaron.Context, log *log.Logger) {
staticHandler(ctx, log, opt)
logger := log.New("static")
return func(ctx *macaron.Context) {
staticHandler(ctx, logger, opt)
}
}