Chore: Fix staticcheck issues (#28860)
* Chore: Fix issues reported by staticcheck Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Undo changes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: Fix issues reported by staticcheck Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix test Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix test Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -111,7 +111,7 @@ func TestAdminApiEndpoint(t *testing.T) {
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "User not found")
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "user not found")
|
||||
|
||||
So(userId, ShouldEqual, 42)
|
||||
So(isDisabled, ShouldEqual, false)
|
||||
@@ -124,7 +124,7 @@ func TestAdminApiEndpoint(t *testing.T) {
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "User not found")
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "user not found")
|
||||
|
||||
So(userId, ShouldEqual, 42)
|
||||
So(isDisabled, ShouldEqual, true)
|
||||
@@ -175,7 +175,7 @@ func TestAdminApiEndpoint(t *testing.T) {
|
||||
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
So(err, ShouldBeNil)
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "User not found")
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "user not found")
|
||||
|
||||
So(userId, ShouldEqual, 42)
|
||||
})
|
||||
@@ -252,7 +252,7 @@ func TestAdminApiEndpoint(t *testing.T) {
|
||||
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
So(err, ShouldBeNil)
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "Organization not found")
|
||||
So(respJSON.Get("message").MustString(), ShouldEqual, "organization not found")
|
||||
|
||||
So(userLogin, ShouldEqual, TestLogin)
|
||||
So(orgId, ShouldEqual, 1000)
|
||||
@@ -276,7 +276,7 @@ func TestAdminApiEndpoint(t *testing.T) {
|
||||
|
||||
respJSON, err := simplejson.NewJson(sc.resp.Body.Bytes())
|
||||
So(err, ShouldBeNil)
|
||||
So(respJSON.Get("error").MustString(), ShouldEqual, "User already exists")
|
||||
So(respJSON.Get("error").MustString(), ShouldEqual, "user already exists")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func createExternalDashboardSnapshot(cmd models.CreateDashboardSnapshotCommand)
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("Create external snapshot response status code %d", response.StatusCode)
|
||||
return nil, fmt.Errorf("create external snapshot response status code %d", response.StatusCode)
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(response.Body).Decode(&createSnapshotResponse); err != nil {
|
||||
@@ -196,7 +196,7 @@ func deleteExternalDashboardSnapshot(externalUrl string) error {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("Unexpected response when deleting external snapshot. Status code: %d", response.StatusCode)
|
||||
return fmt.Errorf("unexpected response when deleting external snapshot, status code: %d", response.StatusCode)
|
||||
}
|
||||
|
||||
// GET /api/snapshots-delete/:deleteKey
|
||||
|
||||
@@ -199,11 +199,11 @@ func (hs *HTTPServer) configureHttps() error {
|
||||
}
|
||||
|
||||
if _, err := os.Stat(setting.CertFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`Cannot find SSL cert_file at %v`, setting.CertFile)
|
||||
return fmt.Errorf(`cannot find SSL cert_file at %q`, setting.CertFile)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(setting.KeyFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`Cannot find SSL key_file at %v`, setting.KeyFile)
|
||||
return fmt.Errorf(`cannot find SSL key_file at %q`, setting.KeyFile)
|
||||
}
|
||||
|
||||
tlsCfg := &tls.Config{
|
||||
@@ -241,11 +241,11 @@ func (hs *HTTPServer) configureHttp2() error {
|
||||
}
|
||||
|
||||
if _, err := os.Stat(setting.CertFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`Cannot find SSL cert_file at %v`, setting.CertFile)
|
||||
return fmt.Errorf(`cannot find SSL cert_file at %q`, setting.CertFile)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(setting.KeyFile); os.IsNotExist(err) {
|
||||
return fmt.Errorf(`Cannot find SSL key_file at %v`, setting.KeyFile)
|
||||
return fmt.Errorf(`cannot find SSL key_file at %q`, setting.KeyFile)
|
||||
}
|
||||
|
||||
tlsCfg := &tls.Config{
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
logger = log.New("LDAP.debug")
|
||||
|
||||
errOrganizationNotFound = func(orgId int64) error {
|
||||
return fmt.Errorf("Unable to find organization with ID '%d'", orgId)
|
||||
return fmt.Errorf("unable to find organization with ID '%d'", orgId)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestGetUserFromLDAPApiEndpoint_OrgNotfound(t *testing.T) {
|
||||
|
||||
expected := `
|
||||
{
|
||||
"error": "Unable to find organization with ID '2'",
|
||||
"error": "unable to find organization with ID '2'",
|
||||
"message": "An organization was not found - Please verify your LDAP configuration"
|
||||
}
|
||||
`
|
||||
@@ -467,7 +467,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenUserNotFound(t *testing.T) {
|
||||
|
||||
expected := `
|
||||
{
|
||||
"message": "User not found"
|
||||
"message": "user not found"
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
@@ -218,30 +218,30 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
|
||||
|
||||
func (proxy *DataSourceProxy) validateRequest() error {
|
||||
if !checkWhiteList(proxy.ctx, proxy.targetUrl.Host) {
|
||||
return errors.New("Target url is not a valid target")
|
||||
return errors.New("target URL is not a valid target")
|
||||
}
|
||||
|
||||
if proxy.ds.Type == models.DS_PROMETHEUS {
|
||||
if proxy.ctx.Req.Request.Method == "DELETE" {
|
||||
return errors.New("Deletes not allowed on proxied Prometheus datasource")
|
||||
return errors.New("deletes not allowed on proxied Prometheus datasource")
|
||||
}
|
||||
if proxy.ctx.Req.Request.Method == "PUT" {
|
||||
return errors.New("Puts not allowed on proxied Prometheus datasource")
|
||||
return errors.New("puts not allowed on proxied Prometheus datasource")
|
||||
}
|
||||
if proxy.ctx.Req.Request.Method == "POST" && !(proxy.proxyPath == "api/v1/query" || proxy.proxyPath == "api/v1/query_range") {
|
||||
return errors.New("Posts not allowed on proxied Prometheus datasource except on /query and /query_range")
|
||||
return errors.New("posts not allowed on proxied Prometheus datasource except on /query and /query_range")
|
||||
}
|
||||
}
|
||||
|
||||
if proxy.ds.Type == models.DS_ES {
|
||||
if proxy.ctx.Req.Request.Method == "DELETE" {
|
||||
return errors.New("Deletes not allowed on proxied Elasticsearch datasource")
|
||||
return errors.New("deletes not allowed on proxied Elasticsearch datasource")
|
||||
}
|
||||
if proxy.ctx.Req.Request.Method == "PUT" {
|
||||
return errors.New("Puts not allowed on proxied Elasticsearch datasource")
|
||||
return errors.New("puts not allowed on proxied Elasticsearch datasource")
|
||||
}
|
||||
if proxy.ctx.Req.Request.Method == "POST" && proxy.proxyPath != "_msearch" {
|
||||
return errors.New("Posts not allowed on proxied Elasticsearch datasource except on /_msearch")
|
||||
return errors.New("posts not allowed on proxied Elasticsearch datasource except on /_msearch")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ func (proxy *DataSourceProxy) validateRequest() error {
|
||||
|
||||
if route.ReqRole.IsValid() {
|
||||
if !proxy.ctx.HasUserRole(route.ReqRole) {
|
||||
return errors.New("Plugin proxy route access denied")
|
||||
return errors.New("plugin proxy route access denied")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func InterpolateURL(anURL *url.URL, route *plugins.AppPluginRoute, orgID int64,
|
||||
if err == nil {
|
||||
result, err = url.Parse(interpolatedResult)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error parsing plugin route url %v", err)
|
||||
return nil, fmt.Errorf("error parsing plugin route URL: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,25 +24,25 @@ func (hs *HTTPServer) RenderToPng(c *models.ReqContext) {
|
||||
|
||||
width, err := strconv.Atoi(queryReader.Get("width", "800"))
|
||||
if err != nil {
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse width as int: %s", err))
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("cannot parse width as int: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
height, err := strconv.Atoi(queryReader.Get("height", "400"))
|
||||
if err != nil {
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse height as int: %s", err))
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("cannot parse height as int: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
timeout, err := strconv.Atoi(queryReader.Get("timeout", "60"))
|
||||
if err != nil {
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse timeout as int: %s", err))
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("cannot parse timeout as int: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
scale, err := strconv.ParseFloat(queryReader.Get("scale", "1"), 64)
|
||||
if err != nil {
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("Cannot parse scale as float: %s", err))
|
||||
c.Handle(400, "Render parameters error", fmt.Errorf("cannot parse scale as float: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user