Replacing interface{} with any everywhere (except generated mocks) (#29446)

Этот коммит содержится в:
Jesús Espino
2024-12-15 21:11:36 +01:00
коммит произвёл GitHub
родитель a21d470bee
Коммит d316df6d28
34 изменённых файлов: 96 добавлений и 96 удалений

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

@@ -21,7 +21,7 @@ import (
func (s *MmctlE2ETestSuite) TestListChannelsCmdF() {
s.SetupTestHelper().InitBasic()
var assertChannelNames = func(want []string, lines []interface{}) {
var assertChannelNames = func(want []string, lines []any) {
var got []string
for i := 0; i < len(lines); i++ {
got = append(got, lines[i].(*model.Channel).Name)

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

@@ -226,9 +226,9 @@ func archiveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) erro
}
if resp.StatusCode == http.StatusOK {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "ok"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "ok"})
} else {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "error"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "error"})
}
return nil
}
@@ -320,9 +320,9 @@ func moveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
}
if resp.StatusCode == http.StatusOK {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "ok"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "ok"})
} else {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "error"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "error"})
}
return nil
}

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

@@ -207,7 +207,7 @@ func (s *MmctlE2ETestSuite) TestArchiveCommandCmdF() {
err := archiveCommandCmdF(c, &cobra.Command{}, []string{command.Id})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 1)
s.Require().Equal(map[string]interface{}{"status": "ok"}, printer.GetLines()[0])
s.Require().Equal(map[string]any{"status": "ok"}, printer.GetLines()[0])
s.Require().Len(printer.GetErrorLines(), 0)
rcommand, err := s.th.App.GetCommand(command.Id)

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

@@ -340,7 +340,7 @@ func (s *MmctlUnitTestSuite) TestArchiveCommandCmd() {
s.Run("Delete without errors", func() {
printer.Clean()
arg := "cmd1"
outputMessage := map[string]interface{}{"status": "ok"}
outputMessage := map[string]any{"status": "ok"}
s.client.
EXPECT().
@@ -358,7 +358,7 @@ func (s *MmctlUnitTestSuite) TestArchiveCommandCmd() {
s.Run("Not able to delete", func() {
printer.Clean()
arg := "cmd1"
outputMessage := map[string]interface{}{"status": "error"}
outputMessage := map[string]any{"status": "error"}
s.client.
EXPECT().
@@ -784,8 +784,8 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() {
}
mockError := errors.New("mock error")
outputMessageOK := map[string]interface{}{"status": "ok"}
outputMessageError := map[string]interface{}{"status": "error"}
outputMessageOK := map[string]any{"status": "ok"}
outputMessageError := map[string]any{"status": "error"}
s.Run("Move custom slash command to another team by id", func() {
printer.Clean()

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

@@ -142,7 +142,7 @@ func init() {
RootCmd.AddCommand(ConfigCmd)
}
func getValue(path []string, obj interface{}) (interface{}, bool) {
func getValue(path []string, obj any) (any, bool) {
r := reflect.ValueOf(obj)
var val reflect.Value
if r.Kind() == reflect.Map {
@@ -187,7 +187,7 @@ func getValue(path []string, obj interface{}) (interface{}, bool) {
return nil, false
}
func setValueWithConversion(val reflect.Value, newValue interface{}) error {
func setValueWithConversion(val reflect.Value, newValue any) error {
switch val.Kind() {
case reflect.Struct:
val.Set(reflect.ValueOf(newValue))
@@ -236,7 +236,7 @@ func setValueWithConversion(val reflect.Value, newValue interface{}) error {
}
}
func setValue(path []string, obj reflect.Value, newValue interface{}) error {
func setValue(path []string, obj reflect.Value, newValue any) error {
var val reflect.Value
switch obj.Kind() {
case reflect.Struct:
@@ -307,7 +307,7 @@ func setConfigValue(path []string, config *model.Config, newValue []string) erro
return setValue(path, reflect.ValueOf(config).Elem(), newValue[0])
}
func resetConfigValue(path []string, config *model.Config, newValue interface{}) error {
func resetConfigValue(path []string, config *model.Config, newValue any) error {
nv := reflect.ValueOf(newValue)
if nv.Kind() == reflect.Ptr {
switch nv.Elem().Kind() {

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

@@ -186,7 +186,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
s.Run("Get value if the key points to a map element", func() {
outputConfig := &model.Config{}
pluginState := &model.PluginState{Enable: true}
pluginSettings := map[string]interface{}{
pluginSettings := map[string]any{
"test1": 1,
"test2": []string{"a", "b"},
"test3": map[string]string{"a": "b"},
@@ -194,7 +194,7 @@ func (s *MmctlUnitTestSuite) TestConfigGetCmd() {
outputConfig.PluginSettings.PluginStates = map[string]*model.PluginState{
"com.mattermost.testplugin": pluginState,
}
outputConfig.PluginSettings.Plugins = map[string]map[string]interface{}{
outputConfig.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.testplugin": pluginSettings,
}
@@ -499,12 +499,12 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
defaultConfig.PluginSettings.PluginStates = map[string]*model.PluginState{
"com.mattermost.testplugin": {Enable: false},
}
pluginSettings := map[string]interface{}{
pluginSettings := map[string]any{
"test1": 1,
"test2": []string{"a", "b"},
"test3": map[string]interface{}{"a": "b"},
"test3": map[string]any{"a": "b"},
}
defaultConfig.PluginSettings.Plugins = map[string]map[string]interface{}{
defaultConfig.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.testplugin": pluginSettings,
}
@@ -513,7 +513,7 @@ func (s *MmctlUnitTestSuite) TestConfigSetCmd() {
inputConfig.PluginSettings.PluginStates = map[string]*model.PluginState{
"com.mattermost.testplugin": {Enable: true},
}
inputConfig.PluginSettings.Plugins = map[string]map[string]interface{}{
inputConfig.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.testplugin": pluginSettings,
}
s.client.

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

@@ -205,7 +205,7 @@ func exportGeneratePresignedURLCmdF(c client.Client, command *cobra.Command, arg
return fmt.Errorf("failed to generate export link: %w", err)
}
printer.PrintT("Export link: {{.Link}}\nExpiration: {{.Expiration}}", map[string]interface{}{
printer.PrintT("Export link: {{.Link}}\nExpiration: {{.Expiration}}", map[string]any{
"Link": presignedURL.URL,
"Expiration": presignedURL.Expiration.String(),
})

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

@@ -98,9 +98,9 @@ func ldapSyncCmdF(c client.Client, cmd *cobra.Command, args []string) error {
}
if resp.StatusCode == http.StatusOK {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "ok"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "ok"})
} else {
printer.PrintT("Status: {{.status}}", map[string]interface{}{"status": "error"})
printer.PrintT("Status: {{.status}}", map[string]any{"status": "error"})
}
return nil

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

@@ -72,7 +72,7 @@ func (s *MmctlE2ETestSuite) TestLdapSyncCmd() {
s.Require().NoError(err)
s.Require().NotEmpty(printer.GetLines())
s.Require().Equal(printer.GetLines()[0], map[string]interface{}{"status": "ok"})
s.Require().Equal(printer.GetLines()[0], map[string]any{"status": "ok"})
s.Require().Len(printer.GetErrorLines(), 0)
// we need to wait a bit for job creation

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

@@ -18,7 +18,7 @@ import (
func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.Run("Sync without errors", func() {
printer.Clean()
outputMessage := map[string]interface{}{"status": "ok"}
outputMessage := map[string]any{"status": "ok"}
s.client.
EXPECT().
@@ -35,7 +35,7 @@ func (s *MmctlUnitTestSuite) TestLdapSyncCmd() {
s.Run("Not able to Sync", func() {
printer.Clean()
outputMessage := map[string]interface{}{"status": "error"}
outputMessage := map[string]any{"status": "error"}
s.client.
EXPECT().

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

@@ -123,7 +123,7 @@ func postCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
return nil
}
func eventDataToPost(eventData map[string]interface{}) (*model.Post, error) {
func eventDataToPost(eventData map[string]any) (*model.Post, error) {
post := &model.Post{}
var rawPost string
for k, v := range eventData {

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

@@ -92,7 +92,7 @@ func parseLogMessage(msg string) (result LogEntry, err error) {
result.Caller = s
default:
var p interface{}
var p any
if err2 := dec.Decode(&p); err2 != nil {
return result, err2
}
@@ -167,7 +167,7 @@ func numberToTime(v json.Number) (time.Time, error) {
// Decodes a value from JSON, coercing it to a string value as necessary
func decodeAsString(dec *json.Decoder) (s string, err error) {
var v interface{}
var v any
if err = dec.Decode(&v); err != nil {
return s, err
}

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

@@ -32,7 +32,7 @@ type Printer struct { //nolint
templateFuncs template.FuncMap
pager bool
Quiet bool
Lines []interface{}
Lines []any
ErrorLines []string
cmd *cobra.Command
@@ -85,7 +85,7 @@ func SetNoNewline(no bool) {
printer.NoNewline = no
}
func SetTemplateFunc(name string, f interface{}) {
func SetTemplateFunc(name string, f any) {
printer.templateFuncs[name] = f
}
@@ -100,7 +100,7 @@ func SetSingle(single bool) {
// PrintT prints an element. Depending on the format, the element can be
// formatted and printed as a structure or used to populate the
// template
func PrintT(templateString string, v interface{}) {
func PrintT(templateString string, v any) {
if printer.Quiet {
return
}
@@ -118,7 +118,7 @@ func PrintT(templateString string, v interface{}) {
}
}
func PrintPreparedT(tpl *template.Template, v interface{}) {
func PrintPreparedT(tpl *template.Template, v any) {
if printer.Quiet {
return
}
@@ -138,7 +138,7 @@ func PrintPreparedT(tpl *template.Template, v interface{}) {
// Print an element. If the format requires a template, the element
// will be printed as a structure with field names using the print
// verb %+v
func Print(v interface{}) {
func Print(v any) {
PrintT("{{printf \"%+v\" .}}", v)
}
@@ -192,7 +192,7 @@ func Flush() error {
printer.printErrors()
defer func() {
printer.Lines = []interface{}{}
printer.Lines = []any{}
printer.ErrorLines = []string{}
}()
@@ -231,12 +231,12 @@ func Flush() error {
// Clean resets the printer's accumulated lines
func Clean() {
printer.Lines = []interface{}{}
printer.Lines = []any{}
printer.ErrorLines = []string{}
}
// GetLines returns the printer's accumulated lines
func GetLines() []interface{} {
func GetLines() []any {
return printer.Lines
}