Skip to content

Commit

Permalink
Chore: use any rather than interface{} (grafana#74066)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu authored Aug 30, 2023
1 parent 3e272d2 commit 025b2f3
Show file tree
Hide file tree
Showing 525 changed files with 2,528 additions and 2,528 deletions.
4 changes: 2 additions & 2 deletions pkg/api/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *contextmod
if err != nil {
return response.Error(http.StatusBadRequest, "alertId is invalid", err)
}
result := make(map[string]interface{})
result := make(map[string]any)
result["alertId"] = alertID

query := alertmodels.GetAlertByIdQuery{ID: alertID}
Expand Down Expand Up @@ -789,7 +789,7 @@ func (hs *HTTPServer) PauseAllAlerts(legacyAlertingEnabled *bool) func(c *contex
pausedState = "paused"
}

result := map[string]interface{}{
result := map[string]any{
"state": resp,
"message": "alerts " + pausedState,
"alertsAffected": updateCmd.ResultCount,
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (hs *HTTPServer) PostGraphiteAnnotation(c *contextmodel.ReqContext) respons
} else {
tagsArray = []string{}
}
case []interface{}:
case []any:
for _, t := range tags {
if tagStr, ok := t.(string); ok {
tagsArray = append(tagsArray, tagStr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func setupSimpleHTTPServer(features *featuremgmt.FeatureManager) *HTTPServer {
}
}

func mockRequestBody(v interface{}) io.ReadCloser {
func mockRequestBody(v any) io.ReadCloser {
b, _ := json.Marshal(v)
return io.NopCloser(bytes.NewReader(b))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@ func (hs *HTTPServer) addGettingStartedPanelToHomeDashboard(c *contextmodel.ReqC

panels := dash.Get("panels").MustArray()

newpanel := simplejson.NewFromAny(map[string]interface{}{
newpanel := simplejson.NewFromAny(map[string]any{
"type": "gettingstarted",
"id": 123123,
"gridPos": map[string]interface{}{
"gridPos": map[string]any{
"x": 0,
"y": 3,
"w": 24,
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dashboard_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type CreateExternalSnapshotResponse struct {

func createExternalDashboardSnapshot(cmd dashboardsnapshots.CreateDashboardSnapshotCommand, externalSnapshotUrl string) (*CreateExternalSnapshotResponse, error) {
var createSnapshotResponse CreateExternalSnapshotResponse
message := map[string]interface{}{
message := map[string]any{
"name": cmd.Name,
"expires": cmd.Expires,
"dashboard": cmd.Dashboard,
Expand Down Expand Up @@ -259,7 +259,7 @@ func deleteExternalDashboardSnapshot(externalUrl string) error {
// Gracefully ignore "snapshot not found" errors as they could have already
// been removed either via the cleanup script or by request.
if resp.StatusCode == 500 {
var respJson map[string]interface{}
var respJson map[string]any
if err := json.NewDecoder(resp.Body).Decode(&respJson); err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
UserID: 5,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
Overwrite: true,
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
UserID: 5,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
Overwrite: true,
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
UserID: 5,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
Overwrite: true,
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {

cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
Dashboard: simplejson.NewFromAny(map[string]interface{}{
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "",
}),
}
Expand Down Expand Up @@ -588,14 +588,14 @@ func TestDashboardAPIEndpoint(t *testing.T) {
{
DashboardID: 1,
Version: 1,
Data: simplejson.NewFromAny(map[string]interface{}{
Data: simplejson.NewFromAny(map[string]any{
"title": "Dash1",
}),
},
{
DashboardID: 2,
Version: 2,
Data: simplejson.NewFromAny(map[string]interface{}{
Data: simplejson.NewFromAny(map[string]any{
"title": "Dash2",
}),
},
Expand Down Expand Up @@ -1142,7 +1142,7 @@ func (m *mockLibraryPanelService) ConnectLibraryPanelsForDashboard(c context.Con
return nil
}

func (m *mockLibraryPanelService) ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []interface{}, folderID int64) error {
func (m *mockLibraryPanelService) ImportLibraryPanelsForDashboard(c context.Context, signedInUser *user.SignedInUser, libraryPanels *simplejson.Json, panels []any, folderID int64) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dataproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type DatasourceProxyRouteParam struct {
type DatasourceProxyPOSTcallsParams struct {
// in:body
// required:true
DatasourceProxyParam interface{}
DatasourceProxyParam any
// in:path
// required:true
DatasourceProxyRoute string `json:"datasource_proxy_route"`
Expand All @@ -166,7 +166,7 @@ type DatasourceProxyPOSTcallsParams struct {
type DatasourceProxyPOSTByUIDcallsParams struct {
// in:body
// required:true
DatasourceProxyParam interface{}
DatasourceProxyParam any
// in:path
// required:true
DatasourceProxyRoute string `json:"datasource_proxy_route"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,14 +839,14 @@ func (hs *HTTPServer) checkDatasourceHealth(c *contextmodel.ReqContext, ds *data
return translatePluginRequestErrorToAPIError(err)
}

payload := map[string]interface{}{
payload := map[string]any{
"status": resp.Status.String(),
"message": resp.Message,
}

// Unmarshal JSONDetails if it's not empty.
if len(resp.JSONDetails) > 0 {
var jsonDetails map[string]interface{}
var jsonDetails map[string]any
err = json.Unmarshal(resp.JSONDetails, &jsonDetails)
if err != nil {
return response.Error(http.StatusInternalServerError, "Failed to unmarshal detailed response from backend plugin", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/datasources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestDataSourcesProxy_userLoggedIn(t *testing.T) {
sc.handlerFunc = hs.GetDataSources
sc.fakeReq("GET", "/api/datasources").exec()

respJSON := []map[string]interface{}{}
respJSON := []map[string]any{}
err := json.NewDecoder(sc.resp.Body).Decode(&respJSON)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dtos/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ type AlertTestResult struct {
}

type AlertTestResultLog struct {
Message string `json:"message"`
Data interface{} `json:"data"`
Message string `json:"message"`
Data any `json:"data"`
}

type EvalMatch struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/dtos/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type MassDeleteAnnotationsCmd struct {
}

type PostGraphiteAnnotationsCmd struct {
When int64 `json:"when"`
What string `json:"what"`
Data string `json:"data"`
Tags interface{} `json:"tags"`
When int64 `json:"when"`
What string `json:"what"`
Data string `json:"data"`
Tags any `json:"tags"`
}
6 changes: 3 additions & 3 deletions pkg/api/dtos/frontend_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ type FrontendSettingsDTO struct {
Reporting FrontendSettingsReportingDTO `json:"reporting"`
UnifiedAlertingEnabled bool `json:"unifiedAlertingEnabled"`
UnifiedAlerting FrontendSettingsUnifiedAlertingDTO `json:"unifiedAlerting"`
Oauth map[string]interface{} `json:"oauth"`
Oauth map[string]any `json:"oauth"`
SamlEnabled bool `json:"samlEnabled"`
SamlName string `json:"samlName"`
TokenExpirationDayLimit int `json:"tokenExpirationDayLimit"`

GeomapDefaultBaseLayerConfig *map[string]interface{} `json:"geomapDefaultBaseLayerConfig,omitempty"`
GeomapDisableCustomBaseLayer bool `json:"geomapDisableCustomBaseLayer"`
GeomapDefaultBaseLayerConfig *map[string]any `json:"geomapDefaultBaseLayerConfig,omitempty"`
GeomapDisableCustomBaseLayer bool `json:"geomapDisableCustomBaseLayer"`

PublicDashboardAccessToken string `json:"publicDashboardAccessToken"`

Expand Down
20 changes: 10 additions & 10 deletions pkg/api/dtos/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func TestGetUniqueDatasourceTypes(t *testing.T) {
desc: "can get unique datasource names",
result: []string{"mysql", "prometheus"},
queries: []*simplejson.Json{
simplejson.NewFromAny(map[string]interface{}{
"datasource": map[string]interface{}{
simplejson.NewFromAny(map[string]any{
"datasource": map[string]any{
"type": "prometheus",
"uid": "uid1",
},
}),
simplejson.NewFromAny(map[string]interface{}{
"datasource": map[string]interface{}{
simplejson.NewFromAny(map[string]any{
"datasource": map[string]any{
"type": "prometheus",
"uid": "uid2",
},
}),
simplejson.NewFromAny(map[string]interface{}{
"datasource": map[string]interface{}{
simplejson.NewFromAny(map[string]any{
"datasource": map[string]any{
"type": "mysql",
"uid": "uid3",
},
Expand All @@ -45,13 +45,13 @@ func TestGetUniqueDatasourceTypes(t *testing.T) {
desc: "returns empty slice when datasources have no type property",
result: []string{},
queries: []*simplejson.Json{
simplejson.NewFromAny(map[string]interface{}{
"datasource": map[string]interface{}{
simplejson.NewFromAny(map[string]any{
"datasource": map[string]any{
"uid": "uid1",
},
}),
simplejson.NewFromAny(map[string]interface{}{
"datasource": map[string]interface{}{
simplejson.NewFromAny(map[string]any{
"datasource": map[string]any{
"uid": "uid3",
},
}),
Expand Down
26 changes: 13 additions & 13 deletions pkg/api/dtos/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
)

type PluginSetting struct {
Name string `json:"name"`
Type string `json:"type"`
Id string `json:"id"`
Enabled bool `json:"enabled"`
Pinned bool `json:"pinned"`
Module string `json:"module"`
BaseUrl string `json:"baseUrl"`
Info plugins.Info `json:"info"`
Includes []*plugins.Includes `json:"includes"`
Dependencies plugins.Dependencies `json:"dependencies"`
JsonData map[string]interface{} `json:"jsonData"`
SecureJsonFields map[string]bool `json:"secureJsonFields"`
DefaultNavUrl string `json:"defaultNavUrl"`
Name string `json:"name"`
Type string `json:"type"`
Id string `json:"id"`
Enabled bool `json:"enabled"`
Pinned bool `json:"pinned"`
Module string `json:"module"`
BaseUrl string `json:"baseUrl"`
Info plugins.Info `json:"info"`
Includes []*plugins.Includes `json:"includes"`
Dependencies plugins.Dependencies `json:"dependencies"`
JsonData map[string]any `json:"jsonData"`
SecureJsonFields map[string]bool `json:"secureJsonFields"`
DefaultNavUrl string `json:"defaultNavUrl"`

LatestVersion string `json:"latestVersion"`
HasUpdate bool `json:"hasUpdate"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/featuremgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ func findResult(t *testing.T, result []featuremgmt.FeatureToggleDTO, name string
return featuremgmt.FeatureToggleDTO{}, false
}

func readBody(t *testing.T, rc io.ReadCloser) map[string]interface{} {
func readBody(t *testing.T, rc io.ReadCloser) map[string]any {
t.Helper()

b, err := io.ReadAll(rc)
require.NoError(t, err)
payload := map[string]interface{}{}
payload := map[string]any{}
require.NoError(t, json.Unmarshal(b, &payload))
return payload
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/folder_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func addFolder(orgID int64, id int64, uid string, parentUID *string) (*f, *dashb
UID: uid,
Version: 1,
Title: title,
Data: simplejson.NewFromAny(map[string]interface{}{"schemaVersion": 17, "title": title, "uid": uid, "version": 1}),
Data: simplejson.NewFromAny(map[string]any{"schemaVersion": 17, "title": title, "uid": uid, "version": 1}),
IsFolder: true,
Created: now,
Updated: now,
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/frontend_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type SourceMapReadRecord struct {
path string
}

type logScenarioFunc func(c *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord)
type logScenarioFunc func(c *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord)

func logGrafanaJavascriptAgentEventScenario(t *testing.T, desc string, event frontendlogging.FrontendGrafanaJavascriptAgentEvent, fn logScenarioFunc) {
t.Run(desc, func(t *testing.T) {
var logcontent = make(map[string]interface{})
var logcontent = make(map[string]any)
logcontent["logger"] = "frontend"
newfrontendLogger := log.Logger(log.LoggerFunc(func(keyvals ...interface{}) error {
newfrontendLogger := log.Logger(log.LoggerFunc(func(keyvals ...any) error {
for i := 0; i < len(keyvals); i += 2 {
logcontent[keyvals[i].(string)] = keyvals[i+1]
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestFrontendLoggingEndpointGrafanaJavascriptAgent(t *testing.T) {
}

logGrafanaJavascriptAgentEventScenario(t, "Should log received error event", errorEvent,
func(sc *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord) {
func(sc *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord) {
assert.Equal(t, http.StatusAccepted, sc.resp.Code)
assertContextContains(t, logs, "logger", "frontend")
assertContextContains(t, logs, "page_url", errorEvent.Meta.Page.URL)
Expand All @@ -161,7 +161,7 @@ func TestFrontendLoggingEndpointGrafanaJavascriptAgent(t *testing.T) {
}

logGrafanaJavascriptAgentEventScenario(t, "Should log received log event", logEvent,
func(sc *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord) {
func(sc *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord) {
assert.Equal(t, http.StatusAccepted, sc.resp.Code)
assert.Len(t, logs, 11)
assertContextContains(t, logs, "logger", "frontend")
Expand All @@ -186,7 +186,7 @@ func TestFrontendLoggingEndpointGrafanaJavascriptAgent(t *testing.T) {
}

logGrafanaJavascriptAgentEventScenario(t, "Should log received log context", logEventWithContext,
func(sc *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord) {
func(sc *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord) {
assert.Equal(t, http.StatusAccepted, sc.resp.Code)
assertContextContains(t, logs, "context_one", "two")
assertContextContains(t, logs, "context_bar", "baz")
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestFrontendLoggingEndpointGrafanaJavascriptAgent(t *testing.T) {
}

logGrafanaJavascriptAgentEventScenario(t, "Should load sourcemap and transform stacktrace line when possible", errorEventForSourceMapping,
func(sc *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord) {
func(sc *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord) {
assert.Equal(t, http.StatusAccepted, sc.resp.Code)
assertContextContains(t, logs, "stacktrace", `UserError: Please replace user and try again
at ? (core|webpack:///./some_source.ts:2:2)
Expand Down Expand Up @@ -285,14 +285,14 @@ func TestFrontendLoggingEndpointGrafanaJavascriptAgent(t *testing.T) {
}

logGrafanaJavascriptAgentEventScenario(t, "Should log web vitals as context", logWebVitals,
func(sc *scenarioContext, logs map[string]interface{}, sourceMapReads []SourceMapReadRecord) {
func(sc *scenarioContext, logs map[string]any, sourceMapReads []SourceMapReadRecord) {
assert.Equal(t, http.StatusAccepted, sc.resp.Code)
assertContextContains(t, logs, "CLS", float64(1))
})
})
}

func assertContextContains(t *testing.T, logRecord map[string]interface{}, label string, value interface{}) {
func assertContextContains(t *testing.T, logRecord map[string]any, label string, value any) {
assert.Contains(t, logRecord, label)
assert.Equal(t, value, logRecord[label])
}
Loading

0 comments on commit 025b2f3

Please sign in to comment.