Chore: Enable Go linter gocritic (#26224)

* Chore: Enable gocritic linter

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-07-16 14:39:01 +02:00
committed by GitHub
parent 317c7b269c
commit d4e4cb4c71
43 changed files with 184 additions and 171 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ func formatShort(interval time.Duration) string {
result += fmt.Sprintf("%dm", mins)
}
remaining = remaining - (mins * time.Minute)
remaining -= (mins * time.Minute)
seconds := remaining / time.Second
if seconds > 0 {
result += fmt.Sprintf("%ds", seconds)
+3 -7
View File
@@ -12,6 +12,8 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
var regNonAlphaNumeric = regexp.MustCompile("[^a-zA-Z0-9]+")
type AnyId struct {
Id int64 `json:"id"`
}
@@ -73,13 +75,7 @@ func GetGravatarUrlWithDefault(text string, defaultText string) string {
return GetGravatarUrl(text)
}
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
return ""
}
text = reg.ReplaceAllString(defaultText, "") + "@localhost"
text = regNonAlphaNumeric.ReplaceAllString(defaultText, "") + "@localhost"
return GetGravatarUrl(text)
}
+4 -3
View File
@@ -159,19 +159,20 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
reqQueryVals := req.URL.Query()
if proxy.ds.Type == models.DS_INFLUXDB_08 {
switch proxy.ds.Type {
case models.DS_INFLUXDB_08:
req.URL.Path = util.JoinURLFragments(proxy.targetUrl.Path, "db/"+proxy.ds.Database+"/"+proxy.proxyPath)
reqQueryVals.Add("u", proxy.ds.User)
reqQueryVals.Add("p", proxy.ds.DecryptedPassword())
req.URL.RawQuery = reqQueryVals.Encode()
} else if proxy.ds.Type == models.DS_INFLUXDB {
case models.DS_INFLUXDB:
req.URL.Path = util.JoinURLFragments(proxy.targetUrl.Path, proxy.proxyPath)
req.URL.RawQuery = reqQueryVals.Encode()
if !proxy.ds.BasicAuth {
req.Header.Del("Authorization")
req.Header.Add("Authorization", util.GetBasicAuthHeader(proxy.ds.User, proxy.ds.DecryptedPassword()))
}
} else {
default:
req.URL.Path = util.JoinURLFragments(proxy.targetUrl.Path, proxy.proxyPath)
}
+3 -10
View File
@@ -51,9 +51,7 @@ func TestRouteSimpleRegister(t *testing.T) {
}
// Setup
rr := NewRouteRegister(func(name string) macaron.Handler {
return emptyHandler(name)
})
rr := NewRouteRegister(emptyHandler)
rr.Delete("/admin", emptyHandler("1"))
rr.Get("/down", emptyHandler("1"), emptyHandler("2"))
@@ -199,10 +197,7 @@ func TestDuplicateRoutShouldPanic(t *testing.T) {
}
}()
rr := NewRouteRegister(func(name string) macaron.Handler {
return emptyHandler(name)
})
rr := NewRouteRegister(emptyHandler)
rr.Get("/api", emptyHandler("1"))
rr.Get("/api", emptyHandler("1"))
@@ -220,9 +215,7 @@ func TestNamedMiddlewareRouteRegister(t *testing.T) {
}
// Setup
rr := NewRouteRegister(func(name string) macaron.Handler {
return emptyHandler(name)
})
rr := NewRouteRegister(emptyHandler)
rr.Delete("/admin", emptyHandler("1"))
rr.Get("/down", emptyHandler("1"), emptyHandler("2"))