fix(backend): enable more Go linters

This commit is contained in:
Łukasz Mierzwa
2022-07-15 18:32:07 +01:00
committed by Łukasz Mierzwa
parent f325dd7590
commit 689866a64c
40 changed files with 136 additions and 50 deletions
+1 -3
View File
@@ -17,9 +17,7 @@ const (
aclActionAllow = "allow"
)
var (
allACLActions = []string{aclActionAllow, aclActionBlock, aclActionRequireMatcher}
)
var allACLActions = []string{aclActionAllow, aclActionBlock, aclActionRequireMatcher}
type silenceFilter struct {
Name string
+1 -1
View File
@@ -25,7 +25,7 @@ func getFiltersFromQuery(filterStrings []string) []filters.FilterT {
return matchFilters
}
func countLabel(countStore map[string]map[string]int, key string, val string) {
func countLabel(countStore map[string]map[string]int, key, val string) {
if _, found := countStore[key]; !found {
countStore[key] = make(map[string]int)
}
+1 -1
View File
@@ -18,7 +18,7 @@ func contentText(w http.ResponseWriter) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
}
func serveFileOr404(path string, contentType string) http.HandlerFunc {
func serveFileOr404(path, contentType string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if path == "" {
+2 -2
View File
@@ -124,7 +124,7 @@ func TestStaticFiles(t *testing.T) {
mime string
}
var staticFileTests = []staticFileTestCase{
staticFileTests := []staticFileTestCase{
{
path: "/favicon.ico",
code: 200,
@@ -185,7 +185,7 @@ func TestStaticFilesPrefix(t *testing.T) {
mime string
}
var staticFilePrefixTests = []staticFileTestCase{
staticFilePrefixTests := []staticFileTestCase{
{
path: "/sub/favicon.ico",
code: 200,
+3 -2
View File
@@ -64,7 +64,7 @@ func TestAuthHeader(t *testing.T) {
defer httpmock.DeactivateAndReset()
for _, testCase := range authHeaderTests {
testCase := testCase //scopelint pin
testCase := testCase // scopelint pin
for _, version := range mock.ListAllMocks() {
apiCache, _ = lru.New(100)
@@ -85,7 +85,8 @@ func TestAuthHeader(t *testing.T) {
"metrics",
"api/v2/status",
"api/v2/silences",
"api/v2/alerts/groups"} {
"api/v2/alerts/groups",
} {
uri := fmt.Sprintf("%s/%s", testCase.alertmanagerURI, m)
+3 -2
View File
@@ -167,7 +167,7 @@ func setupRouter(router *chi.Mux, historyPoller *historyPoller) {
}
}
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
walkFunc := func(method, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Debug().
Str("method", method).
Str("route", route).
@@ -235,6 +235,7 @@ func setupUpstreams() error {
func msgFormatter(msg any) string {
return fmt.Sprintf("msg=%q", msg)
}
func lvlFormatter(level any) string {
if level == nil {
return ""
@@ -425,7 +426,7 @@ func writePidFile() error {
if pidFile != "" {
log.Info().Str("path", pidFile).Msg("Writing PID file")
pid := os.Getpid()
err := os.WriteFile(pidFile, []byte(strconv.Itoa(pid)), 0644)
err := os.WriteFile(pidFile, []byte(strconv.Itoa(pid)), 0o644)
if err != nil {
return fmt.Errorf("failed to write a PID file: %w", err)
}
+1 -1
View File
@@ -213,7 +213,7 @@ func TestProxyHeaders(t *testing.T) {
defer httpmock.DeactivateAndReset()
for _, testCase := range proxyHeaderTests {
testCase := testCase //scopelint pin
testCase := testCase // scopelint pin
r := testRouter()
am, err := alertmanager.NewAlertmanager(
"cluster",
-1
View File
@@ -43,7 +43,6 @@ func TestMain(m *testing.M) {
ecode = 1
}
os.Exit(ecode)
}
func TestScripts(t *testing.T) {
@@ -209,9 +209,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 1234"
level=info msg=" prefix: /prefix/"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
@@ -242,9 +242,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
@@ -104,9 +104,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
+1 -1
View File
@@ -104,9 +104,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
+1 -1
View File
@@ -104,9 +104,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
@@ -114,9 +114,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
@@ -104,9 +104,9 @@ level=info msg=" key: \"\""
level=info msg=" port: 8080"
level=info msg=" prefix: /"
level=info msg="log:"
level=info msg=" config: true"
level=info msg=" level: info"
level=info msg=" format: text"
level=info msg=" config: true"
level=info msg=" requests: false"
level=info msg=" timestamp: false"
level=info msg="receivers:"
+1 -1
View File
@@ -680,7 +680,7 @@ func silences(w http.ResponseWriter, r *http.Request) {
recentFirst = false
}
sort.Slice(dedupedSilences, func(i int, j int) bool {
sort.Slice(dedupedSilences, func(i, j int) bool {
if dedupedSilences[i].Silence.EndsAt.Equal(dedupedSilences[j].Silence.EndsAt) {
if dedupedSilences[i].Silence.StartsAt.Equal(dedupedSilences[j].Silence.StartsAt) {
return dedupedSilences[i].Silence.ID < dedupedSilences[j].Silence.ID
+1
View File
@@ -3044,6 +3044,7 @@ func (ew *gzErrWriter) Write(p []byte) (n int, err error) {
}
return len(p), nil
}
func (ew *gzErrWriter) Close() error {
if ew.failClose {
return errors.New("Close error")