Chore: Enable Go linter gocritic (#26224)
* Chore: Enable gocritic linter Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user