Chore: replace macaron with web package (#40136)

* replace macaron with web package

* add web.go
This commit is contained in:
Serge Zaitsev
2021-10-11 14:30:59 +02:00
committed by GitHub
parent 78ebac0116
commit 57fcfd578d
70 changed files with 369 additions and 375 deletions
+6 -6
View File
@@ -26,7 +26,7 @@ import (
"sync"
"github.com/grafana/grafana/pkg/infra/log"
"gopkg.in/macaron.v1"
"github.com/grafana/grafana/pkg/web"
)
var Root string
@@ -39,7 +39,7 @@ func init() {
}
}
// StaticOptions is a struct for specifying configuration options for the macaron.Static middleware.
// StaticOptions is a struct for specifying configuration options for the web.Static middleware.
type StaticOptions struct {
// Prefix is the optional prefix used to serve the static directory content
Prefix string
@@ -49,7 +49,7 @@ type StaticOptions struct {
IndexFile string
// Expires defines which user-defined function to use for producing a HTTP Expires Header
// https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
AddHeaders func(ctx *macaron.Context)
AddHeaders func(ctx *web.Context)
// FileSystem is the interface for supporting any implementation of file system.
FileSystem http.FileSystem
}
@@ -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 *web.Context, log log.Logger, opt StaticOptions) bool {
if ctx.Req.Method != "GET" && ctx.Req.Method != "HEAD" {
return false
}
@@ -195,11 +195,11 @@ func staticHandler(ctx *macaron.Context, log log.Logger, opt StaticOptions) bool
}
// Static returns a middleware handler that serves static files in the given directory.
func Static(directory string, staticOpt ...StaticOptions) macaron.Handler {
func Static(directory string, staticOpt ...StaticOptions) web.Handler {
opt := prepareStaticOptions(directory, staticOpt)
logger := log.New("static")
return func(ctx *macaron.Context) {
return func(ctx *web.Context) {
staticHandler(ctx, logger, opt)
}
}