Skip to content

Commit

Permalink
Replacing interface{} with any everywhere (except generated mocks) (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino authored Dec 15, 2024
1 parent a21d470 commit d316df6
Show file tree
Hide file tree
Showing 34 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion server/channels/api4/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions server/channels/api4/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions server/channels/app/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand All @@ -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: "",
},
}
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions server/channels/app/notify_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/platform/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/scheduled_post_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/scheduled_post_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/slashcommands/command_exportlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})}
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 16 additions & 16 deletions server/channels/audit/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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())
}
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions server/channels/store/sqlstore/draft_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/channels/store/sqlstore/preference_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions server/channels/store/sqlstore/scheduled_post_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down
8 changes: 4 additions & 4 deletions server/channels/web/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
},
}
Expand Down
2 changes: 1 addition & 1 deletion server/cmd/mmctl/commands/channel_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions server/cmd/mmctl/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/cmd/mmctl/commands/command_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions server/cmd/mmctl/commands/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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().
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit d316df6

Please sign in to comment.