mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Applies perfsprint linter (#24999)
Replacing usages of fmt.Sprint with faster alternatives Signed-off-by: Philippe Antoine <contact@catenacyber.fr>
This commit is contained in:
parent
43f4734eae
commit
04e7b6bc9e
@ -7,9 +7,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -180,7 +180,7 @@ func selfHostedConfirm(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.App.NotifySelfHostedSignupProgress(confirmResponse.Progress, user.Id)
|
c.App.NotifySelfHostedSignupProgress(confirmResponse.Progress, user.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() == fmt.Sprintf("%d", http.StatusUnprocessableEntity) {
|
if err.Error() == strconv.Itoa(http.StatusUnprocessableEntity) {
|
||||||
c.Err = model.NewAppError(where, "api.cloud.app_error", nil, "", http.StatusUnprocessableEntity).Wrap(err)
|
c.Err = model.NewAppError(where, "api.cloud.app_error", nil, "", http.StatusUnprocessableEntity).Wrap(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ func selfHostedConfirmExpand(c *Context, w http.ResponseWriter, r *http.Request)
|
|||||||
c.App.NotifySelfHostedSignupProgress(confirmResponse.Progress, user.Id)
|
c.App.NotifySelfHostedSignupProgress(confirmResponse.Progress, user.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() == fmt.Sprintf("%d", http.StatusUnprocessableEntity) {
|
if err.Error() == strconv.Itoa(http.StatusUnprocessableEntity) {
|
||||||
c.Err = model.NewAppError(where, "api.cloud.app_error", nil, "", http.StatusUnprocessableEntity).Wrap(err)
|
c.Err = model.NewAppError(where, "api.cloud.app_error", nil, "", http.StatusUnprocessableEntity).Wrap(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -343,9 +344,9 @@ func getFormattedPostTime(user *model.User, post *model.Post, useMilitaryTime bo
|
|||||||
|
|
||||||
return formattedPostTime{
|
return formattedPostTime{
|
||||||
Time: localTime,
|
Time: localTime,
|
||||||
Year: fmt.Sprintf("%d", localTime.Year()),
|
Year: strconv.Itoa(localTime.Year()),
|
||||||
Month: translateFunc(localTime.Month().String()),
|
Month: translateFunc(localTime.Month().String()),
|
||||||
Day: fmt.Sprintf("%d", localTime.Day()),
|
Day: strconv.Itoa(localTime.Day()),
|
||||||
Hour: hour,
|
Hour: hour,
|
||||||
Minute: fmt.Sprintf("%02d"+period, localTime.Minute()),
|
Minute: fmt.Sprintf("%02d"+period, localTime.Minute()),
|
||||||
TimeZone: zone,
|
TimeZone: zone,
|
||||||
|
@ -5,6 +5,7 @@ package platform
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost/server/public/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
@ -229,7 +230,7 @@ func (ps *PlatformService) UpdateSessionsIsGuest(c request.CTX, userID string, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
session.AddProp(model.SessionPropIsGuest, fmt.Sprintf("%t", isGuest))
|
session.AddProp(model.SessionPropIsGuest, strconv.FormatBool(isGuest))
|
||||||
err := ps.Store.Session().UpdateProps(session)
|
err := ps.Store.Session().UpdateProps(session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn("Unable to update isGuest session", mlog.Err(err))
|
mlog.Warn("Unable to update isGuest session", mlog.Err(err))
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
package searchtest
|
package searchtest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -352,7 +352,7 @@ func (th *SearchTestHelper) createPostModel(userID, channelID, message, hashtags
|
|||||||
return &model.Post{
|
return &model.Post{
|
||||||
Message: message,
|
Message: message,
|
||||||
ChannelId: channelID,
|
ChannelId: channelID,
|
||||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
PendingPostId: model.NewId() + ":" + strconv.FormatInt(model.GetMillis(), 10),
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
Hashtags: hashtags,
|
Hashtags: hashtags,
|
||||||
IsPinned: pinned,
|
IsPinned: pinned,
|
||||||
|
@ -5,12 +5,12 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"encoding/hex"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HashSha256(text string) string {
|
func HashSha256(text string) string {
|
||||||
hash := sha256.New()
|
hash := sha256.New()
|
||||||
hash.Write([]byte(text))
|
hash.Write([]byte(text))
|
||||||
|
|
||||||
return fmt.Sprintf("%x", hash.Sum(nil))
|
return hex.EncodeToString(hash.Sum(nil))
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/isacikgoz/prompt"
|
"github.com/isacikgoz/prompt"
|
||||||
@ -38,7 +39,7 @@ func checkValidSocket(socketPath string) error {
|
|||||||
return fmt.Errorf("cannot get owner of the file %q", socketPath)
|
return fmt.Errorf("cannot get owner of the file %q", socketPath)
|
||||||
}
|
}
|
||||||
// if user id is "0", they are root and we should avoid this check
|
// if user id is "0", they are root and we should avoid this check
|
||||||
if fmt.Sprint(s.Uid) != cUser.Uid && cUser.Uid != "0" {
|
if strconv.FormatUint(uint64(s.Uid), 10) != cUser.Uid && cUser.Uid != "0" {
|
||||||
return fmt.Errorf("owner of the file %q must be the same user running mmctl", socketPath)
|
return fmt.Errorf("owner of the file %q must be the same user running mmctl", socketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -39,8 +38,8 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li
|
|||||||
props["EnableTesting"] = strconv.FormatBool(*c.ServiceSettings.EnableTesting)
|
props["EnableTesting"] = strconv.FormatBool(*c.ServiceSettings.EnableTesting)
|
||||||
props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper)
|
props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper)
|
||||||
props["EnableClientPerformanceDebugging"] = strconv.FormatBool(*c.ServiceSettings.EnableClientPerformanceDebugging)
|
props["EnableClientPerformanceDebugging"] = strconv.FormatBool(*c.ServiceSettings.EnableClientPerformanceDebugging)
|
||||||
props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit)
|
props["PostEditTimeLimit"] = strconv.Itoa(*c.ServiceSettings.PostEditTimeLimit)
|
||||||
props["MinimumHashtagLength"] = fmt.Sprintf("%v", *c.ServiceSettings.MinimumHashtagLength)
|
props["MinimumHashtagLength"] = strconv.Itoa(*c.ServiceSettings.MinimumHashtagLength)
|
||||||
props["EnablePreviewFeatures"] = strconv.FormatBool(*c.ServiceSettings.EnablePreviewFeatures)
|
props["EnablePreviewFeatures"] = strconv.FormatBool(*c.ServiceSettings.EnablePreviewFeatures)
|
||||||
props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial)
|
props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial)
|
||||||
props["EnableOnboardingFlow"] = strconv.FormatBool(*c.ServiceSettings.EnableOnboardingFlow)
|
props["EnableOnboardingFlow"] = strconv.FormatBool(*c.ServiceSettings.EnableOnboardingFlow)
|
||||||
@ -237,8 +236,8 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m
|
|||||||
props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/")
|
props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/")
|
||||||
props["SiteName"] = *c.TeamSettings.SiteName
|
props["SiteName"] = *c.TeamSettings.SiteName
|
||||||
props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/")
|
props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/")
|
||||||
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
props["WebsocketPort"] = strconv.Itoa(*c.ServiceSettings.WebsocketPort)
|
||||||
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
|
props["WebsocketSecurePort"] = strconv.Itoa(*c.ServiceSettings.WebsocketSecurePort)
|
||||||
props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation)
|
props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation)
|
||||||
props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer)
|
props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer)
|
||||||
props["EnableJoinLeaveMessageByDefault"] = strconv.FormatBool(*c.TeamSettings.EnableJoinLeaveMessageByDefault)
|
props["EnableJoinLeaveMessageByDefault"] = strconv.FormatBool(*c.TeamSettings.EnableJoinLeaveMessageByDefault)
|
||||||
@ -288,7 +287,7 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m
|
|||||||
|
|
||||||
props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable)
|
props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable)
|
||||||
|
|
||||||
props["PasswordMinimumLength"] = fmt.Sprintf("%v", *c.PasswordSettings.MinimumLength)
|
props["PasswordMinimumLength"] = strconv.Itoa(*c.PasswordSettings.MinimumLength)
|
||||||
props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase)
|
props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase)
|
||||||
props["PasswordRequireUppercase"] = strconv.FormatBool(*c.PasswordSettings.Uppercase)
|
props["PasswordRequireUppercase"] = strconv.FormatBool(*c.PasswordSettings.Uppercase)
|
||||||
props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number)
|
props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
package bleveengine
|
package bleveengine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost/server/public/model"
|
"github.com/mattermost/mattermost/server/public/model"
|
||||||
)
|
)
|
||||||
@ -13,7 +13,7 @@ func createPost(userId string, channelId string) *model.Post {
|
|||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
Message: model.NewRandomString(15),
|
Message: model.NewRandomString(15),
|
||||||
ChannelId: channelId,
|
ChannelId: channelId,
|
||||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
PendingPostId: model.NewId() + ":" + strconv.FormatInt(model.GetMillis(), 10),
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
CreateAt: 1000000,
|
CreateAt: 1000000,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user