From d316df6d286a005148295277878456306cfb7e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Sun, 15 Dec 2024 21:11:36 +0100 Subject: [PATCH] Replacing interface{} with any everywhere (except generated mocks) (#29446) --- server/channels/api4/channel.go | 2 +- server/channels/api4/system.go | 4 +-- server/channels/app/audit.go | 8 ++--- server/channels/app/draft.go | 2 +- server/channels/app/elasticsearch.go | 2 +- server/channels/app/file.go | 2 +- server/channels/app/group.go | 2 +- server/channels/app/notify_admin.go | 8 ++--- server/channels/app/platform/config.go | 4 +-- server/channels/app/post.go | 2 +- server/channels/app/scheduled_post_job.go | 4 +-- .../channels/app/scheduled_post_job_test.go | 2 +- .../app/slashcommands/command_exportlink.go | 2 +- server/channels/app/user.go | 2 +- server/channels/audit/record.go | 32 +++++++++---------- server/channels/store/sqlstore/draft_store.go | 4 +-- .../store/sqlstore/preference_store.go | 2 +- .../store/sqlstore/scheduled_post_store.go | 8 ++--- server/channels/web/context.go | 8 ++--- server/cmd/mmctl/commands/channel_e2e_test.go | 2 +- server/cmd/mmctl/commands/command.go | 8 ++--- server/cmd/mmctl/commands/command_e2e_test.go | 2 +- server/cmd/mmctl/commands/command_test.go | 8 ++--- server/cmd/mmctl/commands/config.go | 8 ++--- server/cmd/mmctl/commands/config_test.go | 12 +++---- server/cmd/mmctl/commands/export.go | 2 +- server/cmd/mmctl/commands/ldap.go | 4 +-- server/cmd/mmctl/commands/ldap_e2e_test.go | 2 +- server/cmd/mmctl/commands/ldap_test.go | 4 +-- server/cmd/mmctl/commands/post.go | 2 +- server/cmd/mmctl/printer/human/parser.go | 4 +-- server/cmd/mmctl/printer/printer.go | 16 +++++----- server/config/diff.go | 10 +++--- server/config/environment_test.go | 8 ++--- 34 files changed, 96 insertions(+), 96 deletions(-) diff --git a/server/channels/api4/channel.go b/server/channels/api4/channel.go index 7fc75dd52673..b85b67647fc3 100644 --- a/server/channels/api4/channel.go +++ b/server/channels/api4/channel.go @@ -1774,7 +1774,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) { props := model.StringInterfaceFromJSON(r.Body) var userIds []string - interfaceIds, ok := props["user_ids"].([]interface{}) + interfaceIds, ok := props["user_ids"].([]any) if ok { if len(interfaceIds) > maxListSize { c.SetInvalidParam("user_ids") diff --git a/server/channels/api4/system.go b/server/channels/api4/system.go index 2488557be2dc..0ff3b39a4400 100644 --- a/server/channels/api4/system.go +++ b/server/channels/api4/system.go @@ -401,8 +401,8 @@ func queryLogs(c *Context, w http.ResponseWriter, r *http.Request) { return } - logsJSON := make(map[string][]interface{}) - var result interface{} + logsJSON := make(map[string][]any) + var result any for node, logLines := range logs { for _, log := range logLines { err = json.Unmarshal([]byte(log), &result) diff --git a/server/channels/app/audit.go b/server/channels/app/audit.go index d59406a6e852..4b2dfb321cdb 100644 --- a/server/channels/app/audit.go +++ b/server/channels/app/audit.go @@ -88,7 +88,7 @@ func (a *App) MakeAuditRecord(rctx request.CTX, event string, initialStatus stri rec := &audit.Record{ EventName: event, Status: initialStatus, - Meta: map[string]interface{}{ + Meta: map[string]any{ audit.KeyAPIPath: "", audit.KeyClusterID: a.GetClusterId(), }, @@ -100,9 +100,9 @@ func (a *App) MakeAuditRecord(rctx request.CTX, event string, initialStatus stri XForwardedFor: "", }, EventData: audit.EventData{ - Parameters: map[string]interface{}{}, - PriorState: map[string]interface{}{}, - ResultState: map[string]interface{}{}, + Parameters: map[string]any{}, + PriorState: map[string]any{}, + ResultState: map[string]any{}, ObjectType: "", }, } diff --git a/server/channels/app/draft.go b/server/channels/app/draft.go index 83c20e64bfba..be7eff6b8f7c 100644 --- a/server/channels/app/draft.go +++ b/server/channels/app/draft.go @@ -42,7 +42,7 @@ func (a *App) UpsertDraft(c request.CTX, draft *model.Draft, connectionID string // Check that channel exists and has not been deleted channel, errCh := a.Srv().Store().Channel().Get(draft.ChannelId, true) if errCh != nil { - err := model.NewAppError("CreateDraft", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "draft.channel_id"}, "", http.StatusBadRequest).Wrap(errCh) + err := model.NewAppError("CreateDraft", "api.context.invalid_param.app_error", map[string]any{"Name": "draft.channel_id"}, "", http.StatusBadRequest).Wrap(errCh) return nil, err } diff --git a/server/channels/app/elasticsearch.go b/server/channels/app/elasticsearch.go index 56870730cbfd..06cf04e06e99 100644 --- a/server/channels/app/elasticsearch.go +++ b/server/channels/app/elasticsearch.go @@ -114,7 +114,7 @@ func (a *App) elasticsearchChannelIndexCheck() { } // TODO include a link to changelog - postMessage := i18n.T("app.channel.elasticsearch_channel_index.notify_admin.message", map[string]interface{}{"ElasticsearchSection": elasticsearchSettingsSectionLink}) + postMessage := i18n.T("app.channel.elasticsearch_channel_index.notify_admin.message", map[string]any{"ElasticsearchSection": elasticsearchSettingsSectionLink}) for _, sysAdmin := range sysAdmins { var channel *model.Channel diff --git a/server/channels/app/file.go b/server/channels/app/file.go index 7d12c7a8ddf2..4c05edb79de2 100644 --- a/server/channels/app/file.go +++ b/server/channels/app/file.go @@ -1512,7 +1512,7 @@ func (a *App) GetLastAccessibleFileTime() (int64, *model.AppError) { lastAccessibleFileTime, err := strconv.ParseInt(system.Value, 10, 64) if err != nil { - return 0, model.NewAppError("GetLastAccessibleFileTime", "common.parse_error_int64", map[string]interface{}{"Value": system.Value}, "", http.StatusInternalServerError).Wrap(err) + return 0, model.NewAppError("GetLastAccessibleFileTime", "common.parse_error_int64", map[string]any{"Value": system.Value}, "", http.StatusInternalServerError).Wrap(err) } return lastAccessibleFileTime, nil diff --git a/server/channels/app/group.go b/server/channels/app/group.go index 31157bec5d65..3a388dff1ddb 100644 --- a/server/channels/app/group.go +++ b/server/channels/app/group.go @@ -127,7 +127,7 @@ func (a *App) isUniqueToUsernames(val string) *model.AppError { return model.NewAppError("isUniqueToUsernames", model.NoTranslation, nil, "", http.StatusInternalServerError).Wrap(err) } if user != nil { - return model.NewAppError("isUniqueToUsernames", "app.group.username_conflict", map[string]interface{}{"Username": val}, "", http.StatusBadRequest) + return model.NewAppError("isUniqueToUsernames", "app.group.username_conflict", map[string]any{"Username": val}, "", http.StatusBadRequest) } return nil } diff --git a/server/channels/app/notify_admin.go b/server/channels/app/notify_admin.go index 21104e404703..563f68f31729 100644 --- a/server/channels/app/notify_admin.go +++ b/server/channels/app/notify_admin.go @@ -135,14 +135,14 @@ func (a *App) upgradePlanAdminNotifyPost(c request.CTX, workspaceName string, us props := make(model.StringInterface) T := i18n.GetUserTranslations(admin.Locale) - message := T("app.cloud.upgrade_plan_bot_message", map[string]interface{}{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) + message := T("app.cloud.upgrade_plan_bot_message", map[string]any{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) if len(userBasedData) == 1 { - message = T("app.cloud.upgrade_plan_bot_message_single", map[string]interface{}{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) // todo (allan): investigate if translations library can do this + message = T("app.cloud.upgrade_plan_bot_message_single", map[string]any{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) // todo (allan): investigate if translations library can do this } if trial { - message = T("app.cloud.trial_plan_bot_message", map[string]interface{}{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) + message = T("app.cloud.trial_plan_bot_message", map[string]any{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) if len(userBasedData) == 1 { - message = T("app.cloud.trial_plan_bot_message_single", map[string]interface{}{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) + message = T("app.cloud.trial_plan_bot_message_single", map[string]any{"UsersNum": len(userBasedData), "WorkspaceName": workspaceName}) } } diff --git a/server/channels/app/platform/config.go b/server/channels/app/platform/config.go index de8cd1cd6e6f..235e077c1db8 100644 --- a/server/channels/app/platform/config.go +++ b/server/channels/app/platform/config.go @@ -114,11 +114,11 @@ func (ps *PlatformService) ReloadConfig() error { return nil } -func (ps *PlatformService) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]interface{} { +func (ps *PlatformService) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]any { return ps.configStore.GetEnvironmentOverridesWithFilter(filter) } -func (ps *PlatformService) GetEnvironmentOverrides() map[string]interface{} { +func (ps *PlatformService) GetEnvironmentOverrides() map[string]any { return ps.configStore.GetEnvironmentOverrides() } diff --git a/server/channels/app/post.go b/server/channels/app/post.go index c56595012aff..5201d4d0cfbf 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -1597,7 +1597,7 @@ func (a *App) GetLastAccessiblePostTime() (int64, *model.AppError) { lastAccessiblePostTime, err := strconv.ParseInt(system.Value, 10, 64) if err != nil { - return 0, model.NewAppError("GetLastAccessiblePostTime", "common.parse_error_int64", map[string]interface{}{"Value": system.Value}, "", http.StatusInternalServerError).Wrap(err) + return 0, model.NewAppError("GetLastAccessiblePostTime", "common.parse_error_int64", map[string]any{"Value": system.Value}, "", http.StatusInternalServerError).Wrap(err) } return lastAccessiblePostTime, nil diff --git a/server/channels/app/scheduled_post_job.go b/server/channels/app/scheduled_post_job.go index ebf4dbc441c7..3db85d50ea6d 100644 --- a/server/channels/app/scheduled_post_job.go +++ b/server/channels/app/scheduled_post_job.go @@ -451,7 +451,7 @@ func (a *App) notifyUser(rctx request.CTX, userId string, userFailedMessages []* var messageBuilder strings.Builder totalFailedMessages := len(userFailedMessages) - messageHeader := T("app.scheduled_post.failed_messages", map[string]interface{}{ + messageHeader := T("app.scheduled_post.failed_messages", map[string]any{ "Count": totalFailedMessages, }) messageBuilder.WriteString(messageHeader) @@ -461,7 +461,7 @@ func (a *App) notifyUser(rctx request.CTX, userId string, userFailedMessages []* channelName := channelNames[key.ChannelId] errorReason := getErrorReason(T, key.ErrorCode) - detailedMessage := T("app.scheduled_post.failed_message_detail", map[string]interface{}{ + detailedMessage := T("app.scheduled_post.failed_message_detail", map[string]any{ "Count": count, "ChannelName": channelName, "ErrorReason": errorReason, diff --git a/server/channels/app/scheduled_post_job_test.go b/server/channels/app/scheduled_post_job_test.go index 32b6b5b93eaa..4a2a09116986 100644 --- a/server/channels/app/scheduled_post_job_test.go +++ b/server/channels/app/scheduled_post_job_test.go @@ -384,7 +384,7 @@ func TestHandleFailedScheduledPosts(t *testing.T) { } T := i18n.GetUserTranslations(user.Locale) - messageHeader := T("app.scheduled_post.failed_messages", map[string]interface{}{ + messageHeader := T("app.scheduled_post.failed_messages", map[string]any{ "Count": len(userFailedMessages), }) diff --git a/server/channels/app/slashcommands/command_exportlink.go b/server/channels/app/slashcommands/command_exportlink.go index 49fadac8d098..309ff95552c0 100644 --- a/server/channels/app/slashcommands/command_exportlink.go +++ b/server/channels/app/slashcommands/command_exportlink.go @@ -113,7 +113,7 @@ func (*ExportLinkProvider) DoCommand(a *app.App, c request.CTX, args *model.Comm } // return link - return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_exportlink.link.text", map[string]interface{}{ + return &model.CommandResponse{ResponseType: model.CommandResponseTypeEphemeral, Text: args.T("api.command_exportlink.link.text", map[string]any{ "Link": res.URL, "Expiration": res.Expiration.String(), })} diff --git a/server/channels/app/user.go b/server/channels/app/user.go index 107fbedf2da7..15789f785766 100644 --- a/server/channels/app/user.go +++ b/server/channels/app/user.go @@ -261,7 +261,7 @@ func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*m case errors.Is(nErr, users.AcceptedDomainError): return nil, model.NewAppError("createUserOrGuest", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest).Wrap(nErr) case errors.As(nErr, &nfErr): - return nil, model.NewAppError("createUserOrGuest", nfErr.Id(), map[string]interface{}{"Min": *a.Config().PasswordSettings.MinimumLength}, "", http.StatusBadRequest) + return nil, model.NewAppError("createUserOrGuest", nfErr.Id(), map[string]any{"Min": *a.Config().PasswordSettings.MinimumLength}, "", http.StatusBadRequest) case errors.Is(nErr, users.UserStoreIsEmptyError): return nil, model.NewAppError("createUserOrGuest", "app.user.store_is_empty.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr) case errors.As(nErr, &invErr): diff --git a/server/channels/audit/record.go b/server/channels/audit/record.go index fd516bfc5078..607308f4b763 100644 --- a/server/channels/audit/record.go +++ b/server/channels/audit/record.go @@ -5,20 +5,20 @@ package audit // Record provides a consistent set of fields used for all audit logging. type Record struct { - EventName string `json:"event_name"` - Status string `json:"status"` - EventData EventData `json:"event"` - Actor EventActor `json:"actor"` - Meta map[string]interface{} `json:"meta"` - Error EventError `json:"error,omitempty"` + EventName string `json:"event_name"` + Status string `json:"status"` + EventData EventData `json:"event"` + Actor EventActor `json:"actor"` + Meta map[string]any `json:"meta"` + Error EventError `json:"error,omitempty"` } // EventData contains all event specific data about the modified entity type EventData struct { - Parameters map[string]interface{} `json:"parameters"` // Payload and parameters being processed as part of the request - PriorState map[string]interface{} `json:"prior_state"` // Prior state of the object being modified, nil if no prior state - ResultState map[string]interface{} `json:"resulting_state"` // Resulting object after creating or modifying it - ObjectType string `json:"object_type"` // String representation of the object type. eg. "post" + Parameters map[string]any `json:"parameters"` // Payload and parameters being processed as part of the request + PriorState map[string]any `json:"prior_state"` // Prior state of the object being modified, nil if no prior state + ResultState map[string]any `json:"resulting_state"` // Resulting object after creating or modifying it + ObjectType string `json:"object_type"` // String representation of the object type. eg. "post" } // EventActor is the subject triggering the event @@ -46,7 +46,7 @@ type EventError struct { // AuditableObject returns. For example: it's likely OK to write a user object to the // audit logs, but not the user password in cleartext or hashed form type Auditable interface { - Auditable() map[string]interface{} + Auditable() map[string]any } // Success marks the audit record status as successful. @@ -62,7 +62,7 @@ func (rec *Record) Fail() { // AddEventParameter adds a parameter, e.g. query or post body, to the event func AddEventParameter[T string | bool | int | int64 | []string | map[string]string](rec *Record, key string, val T) { if rec.EventData.Parameters == nil { - rec.EventData.Parameters = make(map[string]interface{}) + rec.EventData.Parameters = make(map[string]any) } rec.EventData.Parameters[key] = val @@ -71,7 +71,7 @@ func AddEventParameter[T string | bool | int | int64 | []string | map[string]str // AddEventParameterAuditable adds an object that is of type Auditable to the event func AddEventParameterAuditable(rec *Record, key string, val Auditable) { if rec.EventData.Parameters == nil { - rec.EventData.Parameters = make(map[string]interface{}) + rec.EventData.Parameters = make(map[string]any) } rec.EventData.Parameters[key] = val.Auditable() @@ -80,10 +80,10 @@ func AddEventParameterAuditable(rec *Record, key string, val Auditable) { // AddEventParameterAuditableArray adds an array of objects of type Auditable to the event func AddEventParameterAuditableArray[T Auditable](rec *Record, key string, val []T) { if rec.EventData.Parameters == nil { - rec.EventData.Parameters = make(map[string]interface{}) + rec.EventData.Parameters = make(map[string]any) } - processedAuditables := make([]map[string]interface{}, 0, len(val)) + processedAuditables := make([]map[string]any, 0, len(val)) for _, auditableVal := range val { processedAuditables = append(processedAuditables, auditableVal.Auditable()) } @@ -108,7 +108,7 @@ func (rec *Record) AddEventObjectType(objectType string) { // AddMeta adds a key/value entry to the audit record that can be used for related information not directly related to // the modified object, e.g. authentication method -func (rec *Record) AddMeta(name string, val interface{}) { +func (rec *Record) AddMeta(name string, val any) { rec.Meta[name] = val } diff --git a/server/channels/store/sqlstore/draft_store.go b/server/channels/store/sqlstore/draft_store.go index 5993b54b7cf7..f3661be5b525 100644 --- a/server/channels/store/sqlstore/draft_store.go +++ b/server/channels/store/sqlstore/draft_store.go @@ -38,8 +38,8 @@ func draftSliceColumns() []string { } } -func draftToSlice(draft *model.Draft) []interface{} { - return []interface{}{ +func draftToSlice(draft *model.Draft) []any { + return []any{ draft.CreateAt, draft.UpdateAt, draft.DeleteAt, diff --git a/server/channels/store/sqlstore/preference_store.go b/server/channels/store/sqlstore/preference_store.go index e48ded99f44d..d1dd0e41f205 100644 --- a/server/channels/store/sqlstore/preference_store.go +++ b/server/channels/store/sqlstore/preference_store.go @@ -319,7 +319,7 @@ func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) { // Delete preference for limit_visible_dms_gms where their value is greater than "40" or less than "1" func (s SqlPreferenceStore) DeleteInvalidVisibleDmsGms() (int64, error) { var queryString string - var args []interface{} + var args []any var err error // We need to pad the value field with zeros when doing comparison's because the value is stored as a string. diff --git a/server/channels/store/sqlstore/scheduled_post_store.go b/server/channels/store/sqlstore/scheduled_post_store.go index b5af54e14223..5c599875c177 100644 --- a/server/channels/store/sqlstore/scheduled_post_store.go +++ b/server/channels/store/sqlstore/scheduled_post_store.go @@ -48,8 +48,8 @@ func (s *SqlScheduledPostStore) columns(prefix string) []string { } } -func (s *SqlScheduledPostStore) scheduledPostToSlice(scheduledPost *model.ScheduledPost) []interface{} { - return []interface{}{ +func (s *SqlScheduledPostStore) scheduledPostToSlice(scheduledPost *model.ScheduledPost) []any { + return []any{ scheduledPost.Id, scheduledPost.CreateAt, scheduledPost.UpdateAt, @@ -230,9 +230,9 @@ func (s *SqlScheduledPostStore) UpdatedScheduledPost(scheduledPost *model.Schedu return nil } -func (s *SqlScheduledPostStore) toUpdateMap(scheduledPost *model.ScheduledPost) map[string]interface{} { +func (s *SqlScheduledPostStore) toUpdateMap(scheduledPost *model.ScheduledPost) map[string]any { now := model.GetMillis() - return map[string]interface{}{ + return map[string]any{ "UpdateAt": now, "Message": scheduledPost.Message, "Props": model.StringInterfaceToJSON(scheduledPost.GetProps()), diff --git a/server/channels/web/context.go b/server/channels/web/context.go index 9cfc117ffcad..cfe6c5fbdee2 100644 --- a/server/channels/web/context.go +++ b/server/channels/web/context.go @@ -71,14 +71,14 @@ func (c *Context) MakeAuditRecord(event string, initialStatus string) *audit.Rec IpAddress: c.AppContext.IPAddress(), XForwardedFor: c.AppContext.XForwardedFor(), }, - Meta: map[string]interface{}{ + Meta: map[string]any{ audit.KeyAPIPath: c.AppContext.Path(), audit.KeyClusterID: c.App.GetClusterId(), }, EventData: audit.EventData{ - Parameters: map[string]interface{}{}, - PriorState: map[string]interface{}{}, - ResultState: map[string]interface{}{}, + Parameters: map[string]any{}, + PriorState: map[string]any{}, + ResultState: map[string]any{}, ObjectType: "", }, } diff --git a/server/cmd/mmctl/commands/channel_e2e_test.go b/server/cmd/mmctl/commands/channel_e2e_test.go index 16622ba0c1e7..9df4dfadc815 100644 --- a/server/cmd/mmctl/commands/channel_e2e_test.go +++ b/server/cmd/mmctl/commands/channel_e2e_test.go @@ -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) diff --git a/server/cmd/mmctl/commands/command.go b/server/cmd/mmctl/commands/command.go index eb1570739315..351be19533a5 100644 --- a/server/cmd/mmctl/commands/command.go +++ b/server/cmd/mmctl/commands/command.go @@ -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 } diff --git a/server/cmd/mmctl/commands/command_e2e_test.go b/server/cmd/mmctl/commands/command_e2e_test.go index 7a427c08788b..73d61e2a06f7 100644 --- a/server/cmd/mmctl/commands/command_e2e_test.go +++ b/server/cmd/mmctl/commands/command_e2e_test.go @@ -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) diff --git a/server/cmd/mmctl/commands/command_test.go b/server/cmd/mmctl/commands/command_test.go index 63a578d377fc..395611151705 100644 --- a/server/cmd/mmctl/commands/command_test.go +++ b/server/cmd/mmctl/commands/command_test.go @@ -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() diff --git a/server/cmd/mmctl/commands/config.go b/server/cmd/mmctl/commands/config.go index 06e194c6b056..4a6e68e6eca0 100644 --- a/server/cmd/mmctl/commands/config.go +++ b/server/cmd/mmctl/commands/config.go @@ -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() { diff --git a/server/cmd/mmctl/commands/config_test.go b/server/cmd/mmctl/commands/config_test.go index 6acb7c6f8a8d..9c3ee45f558d 100644 --- a/server/cmd/mmctl/commands/config_test.go +++ b/server/cmd/mmctl/commands/config_test.go @@ -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. diff --git a/server/cmd/mmctl/commands/export.go b/server/cmd/mmctl/commands/export.go index 2d30f26006e3..077d738aeec0 100644 --- a/server/cmd/mmctl/commands/export.go +++ b/server/cmd/mmctl/commands/export.go @@ -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(), }) diff --git a/server/cmd/mmctl/commands/ldap.go b/server/cmd/mmctl/commands/ldap.go index c26066831499..69175a6c1a18 100644 --- a/server/cmd/mmctl/commands/ldap.go +++ b/server/cmd/mmctl/commands/ldap.go @@ -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 diff --git a/server/cmd/mmctl/commands/ldap_e2e_test.go b/server/cmd/mmctl/commands/ldap_e2e_test.go index 77cfc4d4b62f..bd0622b79ae2 100644 --- a/server/cmd/mmctl/commands/ldap_e2e_test.go +++ b/server/cmd/mmctl/commands/ldap_e2e_test.go @@ -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 diff --git a/server/cmd/mmctl/commands/ldap_test.go b/server/cmd/mmctl/commands/ldap_test.go index cda0cbd6e262..b44c99af37b0 100644 --- a/server/cmd/mmctl/commands/ldap_test.go +++ b/server/cmd/mmctl/commands/ldap_test.go @@ -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(). diff --git a/server/cmd/mmctl/commands/post.go b/server/cmd/mmctl/commands/post.go index f3029e8b0057..0a790de3096a 100644 --- a/server/cmd/mmctl/commands/post.go +++ b/server/cmd/mmctl/commands/post.go @@ -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 { diff --git a/server/cmd/mmctl/printer/human/parser.go b/server/cmd/mmctl/printer/human/parser.go index fd16259bfe48..a3e3e778abb7 100644 --- a/server/cmd/mmctl/printer/human/parser.go +++ b/server/cmd/mmctl/printer/human/parser.go @@ -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 } diff --git a/server/cmd/mmctl/printer/printer.go b/server/cmd/mmctl/printer/printer.go index 183c743cc308..9b02bf0e4d26 100644 --- a/server/cmd/mmctl/printer/printer.go +++ b/server/cmd/mmctl/printer/printer.go @@ -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 } diff --git a/server/config/diff.go b/server/config/diff.go index cdee5d6d52e6..524a404474b4 100644 --- a/server/config/diff.go +++ b/server/config/diff.go @@ -18,20 +18,20 @@ type ConfigDiff struct { ActualVal any `json:"actual_val"` } -func (c *ConfigDiff) Auditable() map[string]interface{} { - return map[string]interface{}{ +func (c *ConfigDiff) Auditable() map[string]any { + return map[string]any{ "path": c.Path, "base_val": c.BaseVal, "actual_val": c.ActualVal, } } -func (cd *ConfigDiffs) Auditable() map[string]interface{} { - var s []interface{} +func (cd *ConfigDiffs) Auditable() map[string]any { + var s []any for _, d := range cd.Sanitize() { s = append(s, d.Auditable()) } - return map[string]interface{}{ + return map[string]any{ "config_diffs": s, } } diff --git a/server/config/environment_test.go b/server/config/environment_test.go index c387c6f7178a..f91d611e7abc 100644 --- a/server/config/environment_test.go +++ b/server/config/environment_test.go @@ -39,7 +39,7 @@ func TestRemoveEnvOverrides(t *testing.T) { Enable: false, }, } - in.PluginSettings.Plugins = map[string]map[string]interface{}{ + in.PluginSettings.Plugins = map[string]map[string]any{ "com.mattermost.plugin-1": { "key1": "value1", }, @@ -71,7 +71,7 @@ func TestRemoveEnvOverrides(t *testing.T) { Enable: true, }, } - in.PluginSettings.Plugins = map[string]map[string]interface{}{ + in.PluginSettings.Plugins = map[string]map[string]any{ "com.mattermost.plugin-1": { "key1": "other-value", }, @@ -166,9 +166,9 @@ func TestRemoveEnvOverrides(t *testing.T) { Enable: true, }, } - in.PluginSettings.Plugins = map[string]map[string]interface{}{ + in.PluginSettings.Plugins = map[string]map[string]any{ "com.mattermost.plugin-1": { - "key": map[string]interface{}{ + "key": map[string]any{ "key": "(?PKEY)-(?P\\d{1,6})(?P[,;]*)", "value": "[$key-$id](https://example.com/?$project-$id)$comma", },