Remove unused Macaron code and interfaces (#37194)

This commit is contained in:
Serge Zaitsev 2021-07-26 11:47:13 +02:00 committed by GitHub
parent e3622ac1da
commit e42a597e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 77 deletions

View File

@ -569,12 +569,7 @@ func TestDataSourceProxy_requestHandling(t *testing.T) {
ds := &models.DataSource{Url: backend.URL, Type: models.DS_GRAPHITE} ds := &models.DataSource{Url: backend.URL, Type: models.DS_GRAPHITE}
responseRecorder := &closeNotifierResponseRecorder{ responseWriter := macaron.NewResponseWriter("GET", httptest.NewRecorder())
ResponseRecorder: httptest.NewRecorder(),
}
t.Cleanup(responseRecorder.Close)
responseWriter := macaron.NewResponseWriter("GET", responseRecorder)
// XXX: Really unsure why, but setting headers within the HTTP handler function doesn't stick, // XXX: Really unsure why, but setting headers within the HTTP handler function doesn't stick,
// so doing it here instead // so doing it here instead
@ -751,20 +746,6 @@ func TestNewDataSourceProxy_MSSQL(t *testing.T) {
} }
} }
type closeNotifierResponseRecorder struct {
*httptest.ResponseRecorder
closeChan chan bool
}
func (r *closeNotifierResponseRecorder) CloseNotify() <-chan bool {
r.closeChan = make(chan bool)
return r.closeChan
}
func (r *closeNotifierResponseRecorder) Close() {
close(r.closeChan)
}
// getDatasourceProxiedRequest is a helper for easier setup of tests based on global config and ReqContext. // getDatasourceProxiedRequest is a helper for easier setup of tests based on global config and ReqContext.
func getDatasourceProxiedRequest(t *testing.T, ctx *models.ReqContext, cfg *setting.Cfg) *http.Request { func getDatasourceProxiedRequest(t *testing.T, ctx *models.ReqContext, cfg *setting.Cfg) *http.Request {
plugin := &plugins.DataSourcePlugin{} plugin := &plugins.DataSourcePlugin{}

View File

@ -23,7 +23,6 @@ import (
"net/http" "net/http"
"os" "os"
"reflect" "reflect"
"strconv"
"strings" "strings"
) )
@ -88,19 +87,10 @@ func validateAndWrapHandler(h Handler) Handler {
// validateAndWrapHandlers preforms validation and wrapping for each input handler. // validateAndWrapHandlers preforms validation and wrapping for each input handler.
// It accepts an optional wrapper function to perform custom wrapping on handlers. // It accepts an optional wrapper function to perform custom wrapping on handlers.
func validateAndWrapHandlers(handlers []Handler, wrappers ...func(Handler) Handler) []Handler { func validateAndWrapHandlers(handlers []Handler) []Handler {
var wrapper func(Handler) Handler
if len(wrappers) > 0 {
wrapper = wrappers[0]
}
wrappedHandlers := make([]Handler, len(handlers)) wrappedHandlers := make([]Handler, len(handlers))
for i, h := range handlers { for i, h := range handlers {
h = validateAndWrapHandler(h) wrappedHandlers[i] = validateAndWrapHandler(h)
if wrapper != nil && !IsFastInvoker(h) {
h = wrapper(h)
}
wrappedHandlers[i] = h
} }
return wrappedHandlers return wrappedHandlers
@ -138,16 +128,6 @@ func New() *Macaron {
return m return m
} }
// Handlers sets the entire middleware stack with the given Handlers.
// This will clear any current middleware handlers,
// and panics if any of the handlers is not a callable function
func (m *Macaron) Handlers(handlers ...Handler) {
m.handlers = make([]Handler, 0)
for _, handler := range handlers {
m.Use(handler)
}
}
// BeforeHandler represents a handler executes at beginning of every request. // BeforeHandler represents a handler executes at beginning of every request.
// Macaron stops future process when it returns true. // Macaron stops future process when it returns true.
type BeforeHandler func(rw http.ResponseWriter, req *http.Request) bool type BeforeHandler func(rw http.ResponseWriter, req *http.Request) bool
@ -229,18 +209,6 @@ func (m *Macaron) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
m.Router.ServeHTTP(rw, req) m.Router.ServeHTTP(rw, req)
} }
func getDefaultListenInfo() (string, int) {
host := os.Getenv("HOST")
if len(host) == 0 {
host = "0.0.0.0"
}
port, _ := strconv.Atoi(os.Getenv("PORT"))
if port == 0 {
port = 4000
}
return host, port
}
// SetURLPrefix sets URL prefix of router layer, so that it support suburl. // SetURLPrefix sets URL prefix of router layer, so that it support suburl.
func (m *Macaron) SetURLPrefix(prefix string) { func (m *Macaron) SetURLPrefix(prefix string) {
m.urlPrefix = prefix m.urlPrefix = prefix

View File

@ -27,7 +27,6 @@ import (
type ResponseWriter interface { type ResponseWriter interface {
http.ResponseWriter http.ResponseWriter
http.Flusher http.Flusher
http.Pusher
// Status returns the status code of the response or 0 if the response has not been written. // Status returns the status code of the response or 0 if the response has not been written.
Status() int Status() int
// Written returns whether or not the ResponseWriter has been written. // Written returns whether or not the ResponseWriter has been written.
@ -97,11 +96,6 @@ func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return hijacker.Hijack() return hijacker.Hijack()
} }
//nolint
func (rw *responseWriter) CloseNotify() <-chan bool {
return rw.ResponseWriter.(http.CloseNotifier).CloseNotify()
}
func (rw *responseWriter) callBefore() { func (rw *responseWriter) callBefore() {
for i := len(rw.beforeFuncs) - 1; i >= 0; i-- { for i := len(rw.beforeFuncs) - 1; i >= 0; i-- {
rw.beforeFuncs[i](rw) rw.beforeFuncs[i](rw)
@ -114,11 +108,3 @@ func (rw *responseWriter) Flush() {
flusher.Flush() flusher.Flush()
} }
} }
func (rw *responseWriter) Push(target string, opts *http.PushOptions) error {
pusher, ok := rw.ResponseWriter.(http.Pusher)
if !ok {
return errors.New("the ResponseWriter doesn't support the Pusher interface")
}
return pusher.Push(target, opts)
}

View File

@ -82,9 +82,6 @@ type Router struct {
groups []group groups []group
notFound http.HandlerFunc notFound http.HandlerFunc
internalServerError func(*Context, error) internalServerError func(*Context, error)
// handlerWrapper is used to wrap arbitrary function from Handler to inject.FastInvoker.
handlerWrapper func(Handler) Handler
} }
func NewRouter() *Router { func NewRouter() *Router {
@ -176,7 +173,7 @@ func (r *Router) Handle(method string, pattern string, handlers []Handler) *Rout
h = append(h, handlers...) h = append(h, handlers...)
handlers = h handlers = h
} }
handlers = validateAndWrapHandlers(handlers, r.handlerWrapper) handlers = validateAndWrapHandlers(handlers)
return r.handle(method, pattern, func(resp http.ResponseWriter, req *http.Request, params Params) { return r.handle(method, pattern, func(resp http.ResponseWriter, req *http.Request, params Params) {
c := r.m.createContext(resp, req) c := r.m.createContext(resp, req)
@ -281,11 +278,6 @@ func (r *Router) InternalServerError(handlers ...Handler) {
} }
} }
// SetHandlerWrapper sets handlerWrapper for the router.
func (r *Router) SetHandlerWrapper(f func(Handler) Handler) {
r.handlerWrapper = f
}
func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if t, ok := r.routers[req.Method]; ok { if t, ok := r.routers[req.Method]; ok {
// Fast match for static routes // Fast match for static routes