Skip to content

Commit

Permalink
Bump Go version to 1.23.6 (mattermost#30242)
Browse files Browse the repository at this point in the history
* Bump Go version to 1.23.6

* Update CodeQL Github action as well

* Use server's Go version for CodeQL action

Co-authored-by: Antonis Stamatiou <stamatiou.antonis@gmail.com>

* Empty commit to trigger CI

* Bump golangci-lint to a version supporting Go 1.23

* Fix golangci-lint warnings

Several rules from gosimple, revive and staticcheck linters were
failing:
- Redefinition of built-in identifiers (max, min, new, recover...)
- Use of printf-like functions with simple strings
- Check for nil slices, when len already takes it into account

---------

Co-authored-by: Antonis Stamatiou <stamatiou.antonis@gmail.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
  • Loading branch information
3 people authored Feb 26, 2025
1 parent 77ae2e2 commit acbbd4c
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: server/go.mod
if: ${{ matrix.language == 'go' }}


Expand Down
2 changes: 1 addition & 1 deletion server/.go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.22.6
1.23.6
2 changes: 1 addition & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ else
endif

golangci-lint: ## Run golangci-lint on codebase
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5

@echo Running golangci-lint
$(GOBIN)/golangci-lint run ./...
Expand Down
2 changes: 1 addition & 1 deletion server/build/Dockerfile.buildenv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.6-bullseye@sha256:0838740c99e64dde1916553b004bdb1bc321823be83bde3d2a1563882eaab7e6
FROM golang:1.23.6-bullseye@sha256:80eb3147ef40b58d527d9c2e634b1a79a750aee09de6f973844db38b33f0550b

RUN apt-get update && apt-get install -y make git apt-transport-https ca-certificates curl software-properties-common build-essential zip xmlsec1 jq pgloader

Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ func (a *App) MFARequired(rctx request.CTX) *model.AppError {
return nil
}

func checkUserLoginAttempts(user *model.User, max int) *model.AppError {
if user.FailedAttempts >= max {
func checkUserLoginAttempts(user *model.User, maxAttempts int) *model.AppError {
if user.FailedAttempts >= maxAttempts {
return model.NewAppError("checkUserLoginAttempts", "api.user.check_user_login_attempts.too_many.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized)
}

Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/import_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
passwordAllChars = passwordSpecialChars + passwordNumbers + passwordUpperCaseLetters + passwordLowerCaseLetters
)

func randInt(max int) (int, error) {
val, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
func randInt(maxInt int) (int, error) {
val, err := rand.Int(rand.Reader, big.NewInt(int64(maxInt)))
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion server/channels/app/notification_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func (a *App) buildFullPushNotificationMessage(c request.CTX, contentsConfig str
}
}

hasFiles := post.FileIds != nil && len(post.FileIds) > 0
hasFiles := len(post.FileIds) > 0

msg.Message = a.getPushNotificationMessage(
contentsConfig,
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ func (ch *Channels) initPlugins(c request.CTX, pluginDir, webappPluginDir string
// Sync plugin active state when config changes. Also notify plugins.
ch.pluginsLock.Lock()
ch.RemoveConfigListener(ch.pluginConfigListenerID)
ch.pluginConfigListenerID = ch.AddConfigListener(func(old, new *model.Config) {
ch.pluginConfigListenerID = ch.AddConfigListener(func(oldCfg, newCfg *model.Config) {
// If plugin status remains unchanged, only then run this.
// Because (*App).InitPlugins is already run as a config change hook.
if *old.PluginSettings.Enable == *new.PluginSettings.Enable {
if *oldCfg.PluginSettings.Enable == *newCfg.PluginSettings.Enable {
ch.syncPluginsActiveState()
}

Expand Down
6 changes: 3 additions & 3 deletions server/channels/app/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ func (a *App) BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataRe
data := &model.SamlMetadataResponse{}
data.IdpDescriptorURL = entityDescriptor.EntityID

if entityDescriptor.IDPSSODescriptors == nil || len(entityDescriptor.IDPSSODescriptors) == 0 {
if len(entityDescriptor.IDPSSODescriptors) == 0 {
err := model.NewAppError("BuildSamlMetadataObject", "api.admin.saml.invalid_xml_missing_idpssodescriptors.app_error", nil, "", http.StatusInternalServerError)
return nil, err
}

idpSSODescriptor := entityDescriptor.IDPSSODescriptors[0]
if idpSSODescriptor.SingleSignOnServices == nil || len(idpSSODescriptor.SingleSignOnServices) == 0 {
if len(idpSSODescriptor.SingleSignOnServices) == 0 {
err := model.NewAppError("BuildSamlMetadataObject", "api.admin.saml.invalid_xml_missing_ssoservices.app_error", nil, "", http.StatusInternalServerError)
return nil, err
}

data.IdpURL = idpSSODescriptor.SingleSignOnServices[0].Location
if idpSSODescriptor.SSODescriptor.RoleDescriptor.KeyDescriptors == nil || len(idpSSODescriptor.SSODescriptor.RoleDescriptor.KeyDescriptors) == 0 {
if len(idpSSODescriptor.SSODescriptor.RoleDescriptor.KeyDescriptors) == 0 {
err := model.NewAppError("BuildSamlMetadataObject", "api.admin.saml.invalid_xml_missing_keydescriptor.app_error", nil, "", http.StatusInternalServerError)
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ func NewServer(options ...Option) (*Server, error) {
return s, nil
}

s.platform.AddConfigListener(func(old, new *model.Config) {
s.platform.AddConfigListener(func(oldCfg, newCfg *model.Config) {
appInstance := New(ServerConnector(s.Channels()))
if *old.GuestAccountsSettings.Enable && !*new.GuestAccountsSettings.Enable {
if *oldCfg.GuestAccountsSettings.Enable && !*newCfg.GuestAccountsSettings.Enable {
c := request.EmptyContext(s.Log())
if appErr := appInstance.DeactivateGuests(c); appErr != nil {
mlog.Error("Unable to deactivate guest accounts", mlog.Err(appErr))
Expand Down
4 changes: 2 additions & 2 deletions server/channels/store/sqlstore/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ func (ss *SqlStore) migrate(direction migrationDirection, dryRun bool) error {
}
}

func (m *Migrator) GeneratePlan(recover bool) (*models.Plan, error) {
func (m *Migrator) GeneratePlan(shouldRecover bool) (*models.Plan, error) {
diff, err := m.engine.Diff(models.Up)
if err != nil {
return nil, err
}

plan, err := m.engine.GeneratePlan(diff, recover)
plan, err := m.engine.GeneratePlan(diff, shouldRecover)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions server/channels/store/sqlstore/team_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,10 @@ func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, restrictions
}

resultQuery := query.Join("Users ru ON (TeamMembers.UserId = ru.Id)")
if restrictions.Teams != nil && len(restrictions.Teams) > 0 {
if len(restrictions.Teams) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("TeamMembers rtm ON ( rtm.UserId = ru.Id AND rtm.DeleteAt = 0 AND rtm.TeamId IN (%s))", sq.Placeholders(len(teams))), teams...)
}
if restrictions.Channels != nil && len(restrictions.Channels) > 0 {
if len(restrictions.Channels) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("ChannelMembers rcm ON ( rcm.UserId = ru.Id AND rcm.ChannelId IN (%s))", sq.Placeholders(len(channels))), channels...)
}

Expand All @@ -1712,10 +1712,10 @@ func applyTeamMemberViewRestrictionsFilterForStats(query sq.SelectBuilder, restr
}

resultQuery := query
if restrictions.Teams != nil && len(restrictions.Teams) > 0 {
if len(restrictions.Teams) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("TeamMembers rtm ON ( rtm.UserId = Users.Id AND rtm.DeleteAt = 0 AND rtm.TeamId IN (%s))", sq.Placeholders(len(teams))), teams...)
}
if restrictions.Channels != nil && len(restrictions.Channels) > 0 {
if len(restrictions.Channels) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("ChannelMembers rcm ON ( rcm.UserId = Users.Id AND rcm.ChannelId IN (%s))", sq.Placeholders(len(channels))), channels...)
}

Expand Down
4 changes: 2 additions & 2 deletions server/channels/store/sqlstore/user_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2037,10 +2037,10 @@ func applyViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.Vie
channels[i] = v
}
resultQuery := query
if restrictions.Teams != nil && len(restrictions.Teams) > 0 {
if len(restrictions.Teams) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("TeamMembers rtm ON ( rtm.UserId = Users.Id AND rtm.DeleteAt = 0 AND rtm.TeamId IN (%s))", sq.Placeholders(len(teams))), teams...)
}
if restrictions.Channels != nil && len(restrictions.Channels) > 0 {
if len(restrictions.Channels) > 0 {
resultQuery = resultQuery.Join(fmt.Sprintf("ChannelMembers rcm ON ( rcm.UserId = Users.Id AND rcm.ChannelId IN (%s))", sq.Placeholders(len(channels))), channels...)
}

Expand Down
2 changes: 1 addition & 1 deletion server/cmd/mmctl/commands/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func docsCmdF(cmd *cobra.Command, args []string) error {
return createErr
}
} else if !fileInfo.IsDir() {
return fmt.Errorf(fmt.Sprintf("File \"%s\" is not a directory", outDir))
return fmt.Errorf("File %q is not a directory", outDir)
}

err = doc.GenReSTTree(RootCmd, outDir)
Expand Down
2 changes: 1 addition & 1 deletion server/config/logconfigsrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
LogConfigSrcTypeFile LogConfigSrcType = "file"
)

type LogSrcListener func(old, new mlog.LoggerConfiguration)
type LogSrcListener func(oldCfg, newCfg mlog.LoggerConfiguration)
type LogConfigSrcType string

// LogConfigSrc abstracts the Advanced Logging configuration so that implementations can
Expand Down
8 changes: 2 additions & 6 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mattermost/mattermost/server/v8

go 1.22.0
go 1.23.0

toolchain go1.22.6
toolchain go1.23.6

require (
code.sajari.com/docconv/v2 v2.0.0-pre.4
Expand Down Expand Up @@ -242,10 +242,6 @@ require (
// github.com/bits-and-blooms/bitset and a couple of dependent repos are yet
// to update their module paths.
exclude (
// goquery requires go >= 1.23. Remove this once we upgrade to 1.23
github.com/PuerkitoBio/goquery v1.9.3
github.com/PuerkitoBio/goquery v1.10.0
github.com/PuerkitoBio/goquery v1.10.1
github.com/RoaringBitmap/roaring v0.7.0
github.com/RoaringBitmap/roaring v0.7.1
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09
Expand Down
16 changes: 8 additions & 8 deletions server/platform/services/searchengine/bleveengine/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ func (b *BleveEngine) SearchPosts(channels model.ChannelList, searchParams []*mo
filters = append(filters, onDateQ)
} else {
if params.AfterDate != "" || params.BeforeDate != "" {
var min, max *float64
var rangeMin, rangeMax *float64
if params.AfterDate != "" {
minf := float64(params.GetAfterDateMillis())
min = &minf
rangeMin = &minf
}

if params.BeforeDate != "" {
maxf := float64(params.GetBeforeDateMillis())
max = &maxf
rangeMax = &maxf
}

dateQ := bleve.NewNumericRangeQuery(min, max)
dateQ := bleve.NewNumericRangeQuery(rangeMin, rangeMax)
dateQ.SetField("CreateAt")
filters = append(filters, dateQ)
}
Expand Down Expand Up @@ -666,18 +666,18 @@ func (b *BleveEngine) SearchFiles(channels model.ChannelList, searchParams []*mo
filters = append(filters, onDateQ)
} else {
if params.AfterDate != "" || params.BeforeDate != "" {
var min, max *float64
var rangeMin, rangeMax *float64
if params.AfterDate != "" {
minf := float64(params.GetAfterDateMillis())
min = &minf
rangeMin = &minf
}

if params.BeforeDate != "" {
maxf := float64(params.GetBeforeDateMillis())
max = &maxf
rangeMax = &maxf
}

dateQ := bleve.NewNumericRangeQuery(min, max)
dateQ := bleve.NewNumericRangeQuery(rangeMin, rangeMax)
dateQ.SetField("CreateAt")
filters = append(filters, dateQ)
}
Expand Down
2 changes: 1 addition & 1 deletion server/platform/shared/mail/inbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func GetMessageFromMailbox(email, id string) (JSONMessageInbucket, error) {
}

// download attachments
if record.Attachments != nil && len(record.Attachments) > 0 {
if len(record.Attachments) > 0 {
for i := range record.Attachments {
var bytes []byte
bytes, err = downloadAttachment(record.Attachments[i].DownloadLink)
Expand Down
4 changes: 2 additions & 2 deletions server/public/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mattermost/mattermost/server/public

go 1.22.0
go 1.23.0

toolchain go1.22.6
toolchain go1.23.6

require (
github.com/blang/semver/v4 v4.0.0
Expand Down
2 changes: 1 addition & 1 deletion server/public/model/client4.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func (c *Client4) DoAPIRequestReader(ctx context.Context, method, url string, da
rq.Header.Set(HeaderAuth, c.AuthType+" "+c.AuthToken)
}

if c.HTTPHeader != nil && len(c.HTTPHeader) > 0 {
if len(c.HTTPHeader) > 0 {
for k, v := range c.HTTPHeader {
rq.Header.Set(k, v)
}
Expand Down
4 changes: 2 additions & 2 deletions server/public/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func (u *User) PreSave() *AppError {
u.Props = make(map[string]string)
}

if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
if len(u.NotifyProps) == 0 {
u.SetDefaultNotifications()
}

Expand Down Expand Up @@ -536,7 +536,7 @@ func (u *User) PreUpdate() {
u.AuthData = nil
}

if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
if len(u.NotifyProps) == 0 {
u.SetDefaultNotifications()
} else if _, ok := u.NotifyProps[MentionKeysNotifyProp]; ok {
// Remove any blank mention keys
Expand Down
4 changes: 2 additions & 2 deletions server/public/model/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func init() {
seen := make(map[string]string)

for _, version := range versions {
maj, min, _ := SplitVersion(version)
verStr := fmt.Sprintf("%v.%v.0", maj, min)
major, minor, _ := SplitVersion(version)
verStr := fmt.Sprintf("%v.%v.0", major, minor)

if seen[verStr] == "" {
versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (l *testLogger) logf(prefix, format string, args ...interface{}) {
measure(l.logContext)
out += fmt.Sprintf(" -- %+v", l.logContext)
}
l.TB.Logf(out)
l.TB.Log(out)
}

func (l *testLogger) Debugf(format string, args ...interface{}) { l.logf("DEBUG", format, args...) }
Expand Down

0 comments on commit acbbd4c

Please sign in to comment.