mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 17:06:49 +00:00
New lint rules
This commit is contained in:
@ -15,7 +15,7 @@ func TestAccessControl(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
|
@ -18,6 +18,6 @@ func AuthCacheInit() {
|
||||
}
|
||||
|
||||
// AuthCacheSet will store the item in memory for the expiration time
|
||||
func AuthCacheSet(k string, x interface{}) {
|
||||
func AuthCacheSet(k string, x any) {
|
||||
AuthCache.Set(k, x, cache.DefaultExpiration)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func TestBodyContext(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
// Create a test handler that checks the context for the body data
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
||||
bodyData := r.Context().Value(c.BodyCtxKey).([]byte)
|
||||
assert.Equal(t, body, bodyData)
|
||||
})
|
||||
|
@ -15,7 +15,7 @@ func TestCors(t *testing.T) {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Cors(r))
|
||||
|
||||
r.Get("/test", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Get("/test", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("test"))
|
||||
})
|
||||
|
||||
@ -48,7 +48,7 @@ func TestOptions(t *testing.T) {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Options(r))
|
||||
|
||||
r.Get("/test", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Get("/test", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("test"))
|
||||
})
|
||||
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
|
||||
"npm/internal/api/middleware"
|
||||
"npm/internal/config"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestEnforceSetup(t *testing.T) {
|
||||
@ -37,7 +37,7 @@ func TestEnforceSetup(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
config.IsSetup = tt.isSetup
|
||||
|
||||
handler := middleware.EnforceSetup()(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := middleware.EnforceSetup()(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
|
@ -23,7 +23,7 @@ func TestExpansion(t *testing.T) {
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
||||
expand := middleware.GetExpandFromContext(r)
|
||||
assert.Equal(t, []string{"item1", "item2"}, expand)
|
||||
})
|
||||
@ -39,7 +39,7 @@ func TestExpansion(t *testing.T) {
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
|
||||
expand := middleware.GetExpandFromContext(r)
|
||||
assert.Nil(t, expand)
|
||||
})
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
// and the sort parameter is valid as well.
|
||||
// After we have determined what the Filters are to be, they are saved on the Context
|
||||
// to be used later in other endpoints.
|
||||
func ListQuery(obj interface{}) func(http.Handler) http.Handler {
|
||||
func ListQuery(obj any) func(http.Handler) http.Handler {
|
||||
schemaData := tags.GetFilterSchema(obj)
|
||||
filterMap := tags.GetFilterMap(obj, "")
|
||||
|
||||
@ -29,13 +29,13 @@ func ListQuery(obj interface{}) func(http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
ctx, statusCode, errMsg, errors := listQueryFilters(r, ctx, schemaData)
|
||||
ctx, statusCode, errMsg, errors := listQueryFilters(ctx, r, schemaData)
|
||||
if statusCode > 0 {
|
||||
h.ResultErrorJSON(w, r, statusCode, errMsg, errors)
|
||||
return
|
||||
}
|
||||
|
||||
ctx, statusCode, errMsg = listQuerySort(r, filterMap, ctx)
|
||||
ctx, statusCode, errMsg = listQuerySort(ctx, r, filterMap)
|
||||
if statusCode > 0 {
|
||||
h.ResultErrorJSON(w, r, statusCode, errMsg, nil)
|
||||
return
|
||||
@ -47,9 +47,9 @@ func ListQuery(obj interface{}) func(http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
func listQuerySort(
|
||||
ctx context.Context,
|
||||
r *http.Request,
|
||||
filterMap map[string]model.FilterMapValue,
|
||||
ctx context.Context,
|
||||
) (context.Context, int, string) {
|
||||
var sortFields []model.Sort
|
||||
|
||||
@ -99,10 +99,10 @@ func listQuerySort(
|
||||
}
|
||||
|
||||
func listQueryFilters(
|
||||
r *http.Request,
|
||||
ctx context.Context,
|
||||
r *http.Request,
|
||||
schemaData string,
|
||||
) (context.Context, int, string, interface{}) {
|
||||
) (context.Context, int, string, any) {
|
||||
reservedFilterKeys := []string{
|
||||
"limit",
|
||||
"offset",
|
||||
|
@ -53,7 +53,7 @@ func TestListQuery(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, c.FiltersCtxKey, tags.GetFilterSchema(testObj))
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
handler := middleware.ListQuery(testObj)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
handler := middleware.ListQuery(testObj)(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
|
@ -33,7 +33,6 @@ func CheckRequestSchema(ctx context.Context, schemaData string, payload []byte)
|
||||
func EnforceRequestSchema(schemaData string) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Get content from context
|
||||
bodyBytes, _ := r.Context().Value(c.BodyCtxKey).([]byte)
|
||||
|
||||
|
Reference in New Issue
Block a user