mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: use any rather than interface{} (#74066)
This commit is contained in:
@@ -54,7 +54,7 @@ LEFT JOIN ` + user + ` AS u2 ON le.updated_by = u2.id
|
||||
}
|
||||
|
||||
func syncFieldsWithModel(libraryElement *model.LibraryElement) error {
|
||||
var modelLibraryElement map[string]interface{}
|
||||
var modelLibraryElement map[string]any
|
||||
if err := json.Unmarshal(libraryElement.Model, &modelLibraryElement); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ func (l *LibraryElementService) DeleteLibraryElementsInFolder(c context.Context,
|
||||
}
|
||||
|
||||
func (l *LibraryElementService) addUidToLibraryPanel(model []byte, newUid string) (json.RawMessage, error) {
|
||||
var modelMap map[string]interface{}
|
||||
var modelMap map[string]any
|
||||
err := json.Unmarshal(model, &modelMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if libraryPanel, ok := modelMap["libraryPanel"].(map[string]interface{}); ok {
|
||||
if libraryPanel, ok := modelMap["libraryPanel"].(map[string]any); ok {
|
||||
if uid, ok := libraryPanel["uid"]; ok && uid == "" {
|
||||
libraryPanel["uid"] = newUid
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "A description",
|
||||
"id": float64(1),
|
||||
@@ -81,7 +81,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "A description",
|
||||
"id": float64(1),
|
||||
@@ -156,7 +156,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "A description",
|
||||
"id": float64(1),
|
||||
|
||||
@@ -43,26 +43,26 @@ func TestDeleteLibraryElement(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to delete a library panel that is connected, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
dashJSON := map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
dashJSON := map[string]any{
|
||||
"panels": []any{
|
||||
map[string]any{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"libraryPanel": map[string]any{
|
||||
"uid": sc.initialResult.Result.UID,
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestGetLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "A description",
|
||||
"id": float64(1),
|
||||
@@ -92,26 +92,26 @@ func TestGetLibraryElement(t *testing.T) {
|
||||
|
||||
scenarioWithPanel(t, "When an admin tries to get a connected library panel, it should succeed and return correct connected dashboards",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
dashJSON := map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
dashJSON := map[string]any{
|
||||
"panels": []any{
|
||||
map[string]any{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"libraryPanel": map[string]any{
|
||||
"uid": sc.initialResult.Result.UID,
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
@@ -137,7 +137,7 @@ func TestGetLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "text",
|
||||
Description: "A description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "A description",
|
||||
"id": float64(1),
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestPatchLibraryElement(t *testing.T) {
|
||||
Kind: int64(model.PanelElement),
|
||||
Type: "graph",
|
||||
Description: "An updated description",
|
||||
Model: map[string]interface{}{
|
||||
Model: map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"description": "An updated description",
|
||||
"id": float64(1),
|
||||
@@ -219,7 +219,7 @@ func TestPatchLibraryElement(t *testing.T) {
|
||||
var result = validateAndUnMarshalResponse(t, resp)
|
||||
sc.initialResult.Result.Type = "graph"
|
||||
sc.initialResult.Result.Description = "New description"
|
||||
sc.initialResult.Result.Model = map[string]interface{}{
|
||||
sc.initialResult.Result.Model = map[string]any{
|
||||
"title": "New Model Title",
|
||||
"name": "New Model Name",
|
||||
"type": "graph",
|
||||
@@ -248,7 +248,7 @@ func TestPatchLibraryElement(t *testing.T) {
|
||||
var result = validateAndUnMarshalResponse(t, resp)
|
||||
sc.initialResult.Result.Type = "text"
|
||||
sc.initialResult.Result.Description = "New description"
|
||||
sc.initialResult.Result.Model = map[string]interface{}{
|
||||
sc.initialResult.Result.Model = map[string]any{
|
||||
"type": "text",
|
||||
"description": "New description",
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func TestPatchLibraryElement(t *testing.T) {
|
||||
var result = validateAndUnMarshalResponse(t, resp)
|
||||
sc.initialResult.Result.Type = "graph"
|
||||
sc.initialResult.Result.Description = "A description"
|
||||
sc.initialResult.Result.Model = map[string]interface{}{
|
||||
sc.initialResult.Result.Model = map[string]any{
|
||||
"type": "graph",
|
||||
"description": "A description",
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func TestPatchLibraryElement(t *testing.T) {
|
||||
sc.initialResult.Result.Type = "text"
|
||||
sc.initialResult.Result.Kind = int64(model.PanelElement)
|
||||
sc.initialResult.Result.Description = "A description"
|
||||
sc.initialResult.Result.Model = map[string]interface{}{
|
||||
sc.initialResult.Result.Model = map[string]any{
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"id": float64(1),
|
||||
"title": "Text - Library Panel",
|
||||
|
||||
@@ -52,26 +52,26 @@ const userInDbAvatar = "/avatar/402d08de060496d6b6874495fe20f5ad"
|
||||
func TestDeleteLibraryPanelsInFolder(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to delete a folder that contains connected library elements, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
dashJSON := map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
dashJSON := map[string]any{
|
||||
"panels": []any{
|
||||
map[string]any{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"libraryPanel": map[string]any{
|
||||
"uid": sc.initialResult.Result.UID,
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
@@ -125,26 +125,26 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) {
|
||||
func TestGetLibraryPanelConnections(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to get connections of library panel, it should succeed and return correct result",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
dashJSON := map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
dashJSON := map[string]any{
|
||||
"panels": []any{
|
||||
map[string]any{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"gridPos": map[string]any{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"libraryPanel": map[string]any{
|
||||
"uid": sc.initialResult.Result.UID,
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
@@ -198,7 +198,7 @@ type libraryElement struct {
|
||||
Kind int64 `json:"kind"`
|
||||
Type string `json:"type"`
|
||||
Description string `json:"description"`
|
||||
Model map[string]interface{} `json:"model"`
|
||||
Model map[string]any `json:"model"`
|
||||
Version int64 `json:"version"`
|
||||
Meta model.LibraryElementDTOMeta `json:"meta"`
|
||||
}
|
||||
@@ -488,7 +488,7 @@ func getCompareOptions() []cmp.Option {
|
||||
}
|
||||
}
|
||||
|
||||
func mockRequestBody(v interface{}) io.ReadCloser {
|
||||
func mockRequestBody(v any) io.ReadCloser {
|
||||
b, _ := json.Marshal(v)
|
||||
return io.NopCloser(bytes.NewReader(b))
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
|
||||
type Pair struct {
|
||||
key string
|
||||
value interface{}
|
||||
value any
|
||||
}
|
||||
|
||||
func selectLibraryElementByParam(params []Pair) (string, []interface{}) {
|
||||
func selectLibraryElementByParam(params []Pair) (string, []any) {
|
||||
conditions := make([]string, 0, len(params))
|
||||
values := make([]interface{}, 0, len(params))
|
||||
values := make([]any, 0, len(params))
|
||||
for _, p := range params {
|
||||
conditions = append(conditions, "le."+p.key+"=?")
|
||||
values = append(values, p.value)
|
||||
@@ -48,7 +48,7 @@ func writeKindSQL(query model.SearchLibraryElementsQuery, builder *db.SQLBuilder
|
||||
func writeTypeFilterSQL(typeFilter []string, builder *db.SQLBuilder) {
|
||||
if len(typeFilter) > 0 {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
params := make([]any, 0)
|
||||
sql.WriteString(` AND le.type IN (?` + strings.Repeat(",?", len(typeFilter)-1) + ")")
|
||||
for _, filter := range typeFilter {
|
||||
params = append(params, filter)
|
||||
@@ -129,7 +129,7 @@ func parseFolderFilter(query model.SearchLibraryElementsQuery) FolderFilter {
|
||||
|
||||
func (f *FolderFilter) writeFolderFilterSQL(includeGeneral bool, builder *db.SQLBuilder) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
params := make([]any, 0)
|
||||
for _, filter := range f.folderIDs {
|
||||
folderID, err := strconv.ParseInt(filter, 10, 64)
|
||||
if err != nil {
|
||||
@@ -145,7 +145,7 @@ func (f *FolderFilter) writeFolderFilterSQL(includeGeneral bool, builder *db.SQL
|
||||
builder.Write(sql.String(), params...)
|
||||
}
|
||||
|
||||
paramsUIDs := make([]interface{}, 0)
|
||||
paramsUIDs := make([]any, 0)
|
||||
for _, folderUID := range f.folderUIDs {
|
||||
if !includeGeneral && isUIDGeneralFolder(folderUID) {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user