From 481d83a1e76415c7e64f2314a7d288ec1ae7aa4f Mon Sep 17 00:00:00 2001 From: Mukul Rawat Date: Sun, 14 Oct 2018 20:54:06 +0530 Subject: [MM-12537] Migrate to idiomatic error handling the file `app/status.go` in the mattermost-server (#9574) (#9589) * Perform idiomatic error handling * Golint gives warning when using the variable name 'userId' so change it to 'userID' * Change all ID back to Id --- app/status.go | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'app') diff --git a/app/status.go b/app/status.go index bfeb5c77e..bda20b22f 100644 --- a/app/status.go +++ b/app/status.go @@ -44,9 +44,7 @@ func (a *App) GetAllStatuses() map[string]*model.Status { statusMap := map[string]*model.Status{} for _, userId := range userIds { - if id, ok := userId.(string); !ok { - continue - } else { + if id, ok := userId.(string); ok { status := GetStatusFromCache(id) if status != nil { statusMap[id] = status @@ -81,16 +79,17 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model } if len(missingUserIds) > 0 { - if result := <-a.Srv.Store.Status().GetByIds(missingUserIds); result.Err != nil { + result := <-a.Srv.Store.Status().GetByIds(missingUserIds) + if result.Err != nil { return nil, result.Err - } else { - statuses := result.Data.([]*model.Status) + } + statuses := result.Data.([]*model.Status) - for _, s := range statuses { - a.AddStatusCacheSkipClusterSend(s) - statusMap[s.UserId] = s.Status - } + for _, s := range statuses { + a.AddStatusCacheSkipClusterSend(s) + statusMap[s.UserId] = s.Status } + } // For the case where the user does not have a row in the Status table and cache @@ -128,17 +127,18 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap } if len(missingUserIds) > 0 { - if result := <-a.Srv.Store.Status().GetByIds(missingUserIds); result.Err != nil { + result := <-a.Srv.Store.Status().GetByIds(missingUserIds) + if result.Err != nil { return nil, result.Err - } else { - statuses := result.Data.([]*model.Status) - - for _, s := range statuses { - a.AddStatusCacheSkipClusterSend(s) - } + } + statuses := result.Data.([]*model.Status) - statusMap = append(statusMap, statuses...) + for _, s := range statuses { + a.AddStatusCacheSkipClusterSend(s) } + + statusMap = append(statusMap, statuses...) + } // For the case where the user does not have a row in the Status table and cache @@ -185,8 +185,8 @@ func (a *App) SetStatusOnline(userId string, manual bool) { broadcast := false var oldStatus string = model.STATUS_OFFLINE - var oldTime int64 = 0 - var oldManual bool = false + var oldTime int64 + var oldManual bool var status *model.Status var err *model.AppError @@ -353,11 +353,11 @@ func (a *App) GetStatus(userId string) (*model.Status, *model.AppError) { return status, nil } - if result := <-a.Srv.Store.Status().Get(userId); result.Err != nil { + result := <-a.Srv.Store.Status().Get(userId) + if result.Err != nil { return nil, result.Err - } else { - return result.Data.(*model.Status), nil } + return result.Data.(*model.Status), nil } func (a *App) IsUserAway(lastActivityAt int64) bool { -- cgit v1.2.3-1-g7c22