* replace interface{} with any
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-07-05 09:46:50 +03:00
коммит произвёл GitHub
родитель b45ff0be5d
Коммит 717a4d04a9
258 изменённых файлов: 1286 добавлений и 1286 удалений

Просмотреть файл

@@ -119,7 +119,7 @@ func RenderMobileError(config *model.Config, w http.ResponseWriter, err *model.A
<h2> `+i18n.T("error")+` </h2>
<p> `+err.Message+` </p>
<a href="`+link+`">
`+i18n.T("api.back_to_app", map[string]interface{}{"SiteName": config.TeamSettings.SiteName})+`
`+i18n.T("api.back_to_app", map[string]any{"SiteName": config.TeamSettings.SiteName})+`
</a>
`)
}

Просмотреть файл

@@ -35,7 +35,7 @@ type MergeConfig struct {
// retTS := ret.(testStruct)
// return &retTS, nil
// }
func Merge(base interface{}, patch interface{}, mergeConfig *MergeConfig) (interface{}, error) {
func Merge(base any, patch any, mergeConfig *MergeConfig) (any, error) {
if reflect.TypeOf(base) != reflect.TypeOf(patch) {
return nil, fmt.Errorf(
"cannot merge different types. base type: %s, patch type: %s",

Просмотреть файл

@@ -286,12 +286,12 @@ func TestMergeWithMaps(t *testing.T) {
assert.Equal(t, 23, *merged["are belong"]["to us"])
})
t.Run("merge map[string]interface{}", func(t *testing.T) {
m1 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
t.Run("merge map[string]any", func(t *testing.T) {
m1 := map[string]any{"this": map[string]*int{"second": newInt(99)},
"base": map[string]*int{"level": newInt(10)}}
m2 := map[string]interface{}{"this": map[string]*int{"second": newInt(77)},
m2 := map[string]any{"this": map[string]*int{"second": newInt(77)},
"patch": map[string]*int{"level": newInt(15)}}
expected := map[string]interface{}{"this": map[string]*int{"second": newInt(77)},
expected := map[string]any{"this": map[string]*int{"second": newInt(77)},
"patch": map[string]*int{"level": newInt(15)}}
merged, err := mergeInterfaceMap(m1, m2)
@@ -300,10 +300,10 @@ func TestMergeWithMaps(t *testing.T) {
assert.Equal(t, expected, merged)
})
t.Run("merge map[string]interface{}, patch has nil keys -- /do/ overwrite base with nil", func(t *testing.T) {
m1 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)}}
m2 := map[string]interface{}{"this": map[string]*int{"second": nil}}
expected := map[string]interface{}{"this": map[string]*int{"second": nil}}
t.Run("merge map[string]any, patch has nil keys -- /do/ overwrite base with nil", func(t *testing.T) {
m1 := map[string]any{"this": map[string]*int{"second": newInt(99)}}
m2 := map[string]any{"this": map[string]*int{"second": nil}}
expected := map[string]any{"this": map[string]*int{"second": nil}}
merged, err := mergeInterfaceMap(m1, m2)
require.NoError(t, err)
@@ -311,12 +311,12 @@ func TestMergeWithMaps(t *testing.T) {
assert.Equal(t, expected, merged)
})
t.Run("merge map[string]interface{}, patch has nil keys -- /do/ overwrite base with nil (more complex)", func(t *testing.T) {
m1 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
t.Run("merge map[string]any, patch has nil keys -- /do/ overwrite base with nil (more complex)", func(t *testing.T) {
m1 := map[string]any{"this": map[string]*int{"second": newInt(99)},
"base": map[string]*int{"level": newInt(10)}}
m2 := map[string]interface{}{"this": map[string]*int{"second": nil},
m2 := map[string]any{"this": map[string]*int{"second": nil},
"base": nil, "patch": map[string]*int{"level": newInt(15)}}
expected := map[string]interface{}{"this": map[string]*int{"second": nil},
expected := map[string]any{"this": map[string]*int{"second": nil},
"base": nil, "patch": map[string]*int{"level": newInt(15)}}
merged, err := mergeInterfaceMap(m1, m2)
@@ -326,9 +326,9 @@ func TestMergeWithMaps(t *testing.T) {
})
t.Run("merge map[string]map[string]*int, base has nil vals -- overwrite base with patch", func(t *testing.T) {
m1 := map[string]interface{}{"base": nil}
m2 := map[string]interface{}{"base": map[string]*int{"level": newInt(10)}}
expected := map[string]interface{}{"base": map[string]*int{"level": newInt(10)}}
m1 := map[string]any{"base": nil}
m2 := map[string]any{"base": map[string]*int{"level": newInt(10)}}
expected := map[string]any{"base": map[string]*int{"level": newInt(10)}}
merged, err := mergeInterfaceMap(m1, m2)
require.NoError(t, err)
@@ -337,10 +337,10 @@ func TestMergeWithMaps(t *testing.T) {
})
t.Run("merge map[string]map[string]*int, base has nil vals -- overwrite base with patch (more complex)", func(t *testing.T) {
m1 := map[string]interface{}{"this": map[string]*int{"second": nil}, "base": nil}
m2 := map[string]interface{}{"this": map[string]*int{"second": newInt(77)},
m1 := map[string]any{"this": map[string]*int{"second": nil}, "base": nil}
m2 := map[string]any{"this": map[string]*int{"second": newInt(77)},
"base": map[string]*int{"level": newInt(10)}, "patch": map[string]*int{"level": newInt(15)}}
expected := map[string]interface{}{"this": map[string]*int{"second": newInt(77)},
expected := map[string]any{"this": map[string]*int{"second": newInt(77)},
"base": map[string]*int{"level": newInt(10)}, "patch": map[string]*int{"level": newInt(15)}}
merged, err := mergeInterfaceMap(m1, m2)
@@ -349,12 +349,12 @@ func TestMergeWithMaps(t *testing.T) {
assert.Equal(t, expected, merged)
})
t.Run("merge map[string]interface{}, pointers are not copied - changes in base do not affect merged", func(t *testing.T) {
m1 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
t.Run("merge map[string]any, pointers are not copied - changes in base do not affect merged", func(t *testing.T) {
m1 := map[string]any{"this": map[string]*int{"second": newInt(99)},
"base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}}
m2 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
m2 := map[string]any{"this": map[string]*int{"second": newInt(99)},
"base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}}
expected := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
expected := map[string]any{"this": map[string]*int{"second": newInt(99)},
"base": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}}
merged, err := mergeInterfaceMap(m1, m2)
@@ -375,11 +375,11 @@ func TestMergeWithMaps(t *testing.T) {
assert.Equal(t, 23, *merged["are belong"].(map[string]*int)["to us"])
})
t.Run("merge map[string]interface{}, pointers are not copied - change in patch do not affect merged", func(t *testing.T) {
m1 := map[string]interface{}{"base": map[string]*int{"level": newInt(15)}}
m2 := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
t.Run("merge map[string]any, pointers are not copied - change in patch do not affect merged", func(t *testing.T) {
m1 := map[string]any{"base": map[string]*int{"level": newInt(15)}}
m2 := map[string]any{"this": map[string]*int{"second": newInt(99)},
"patch": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}}
expected := map[string]interface{}{"this": map[string]*int{"second": newInt(99)},
expected := map[string]any{"this": map[string]*int{"second": newInt(99)},
"patch": map[string]*int{"level": newInt(10)}, "are belong": map[string]*int{"to us": newInt(23)}}
merged, err := mergeInterfaceMap(m1, m2)
@@ -1652,12 +1652,12 @@ func mergeMapOfMap(base, patch map[string]map[string]*int) (map[string]map[strin
return retTS, nil
}
func mergeInterfaceMap(base, patch map[string]interface{}) (map[string]interface{}, error) {
func mergeInterfaceMap(base, patch map[string]any) (map[string]any, error) {
ret, err := utils.Merge(base, patch, nil)
if err != nil {
return nil, err
}
retTS := ret.(map[string]interface{})
retTS := ret.(map[string]any)
return retTS, nil
}