MM-49703: Bump to Go 1.19 (#4489) (#4502)

Also fix some gofmt issues

https://mattermost.atlassian.net/browse/MM-49703
pull/4396/head^2
Agniva De Sarker 1 year ago committed by GitHub
parent 50e15f3804
commit d6207dde6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .github/workflows/ci.yml
  2. 8
      .github/workflows/dev-release.yml
  3. 4
      .github/workflows/lint-server.yml
  4. 8
      .github/workflows/prod-release.yml
  5. 2
      .gitlab-ci.yml
  6. 2
      build/gowork/main.go
  7. 2
      linux/go.mod
  8. 2
      mattermost-plugin/build/go.mod
  9. 2
      mattermost-plugin/go.mod
  10. 3
      server/.golangci.yml
  11. 4
      server/api/api.go
  12. 2
      server/api/audit.go
  13. 5
      server/api/auth.go
  14. 2
      server/api/members.go
  15. 2
      server/app/insights.go
  16. 4
      server/app/insights_test.go
  17. 1
      server/assets/assets.go
  18. 2
      server/go.mod
  19. 2
      server/go.tools.mod
  20. 2
      server/integrationtests/cards_test.go
  21. 4
      server/main/main.go
  22. 2
      server/server/server.go
  23. 8
      server/services/audit/audit.go
  24. 2
      server/services/metrics/service.go
  25. 2
      server/services/store/mattermostauthlayer/mattermostauthlayer.go
  26. 8
      server/services/store/mockstore/mockstore.go
  27. 2
      server/services/store/sqlstore/board_insights.go
  28. 6
      server/services/store/sqlstore/public_methods.go
  29. 4
      server/services/store/sqlstore/sqlstore.go
  30. 2
      server/services/store/store.go
  31. 2
      server/services/store/storetests/board_insights.go
  32. 3
      server/web/webserver.go
  33. 12
      server/ws/plugin_adapter.go
  34. 3
      server/ws/plugin_adapter_cluster.go

@ -48,7 +48,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: "Test server: ${{matrix['db']}}"
run: cd focalboard; make server-test-${{matrix['db']}}
@ -83,7 +83,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Setup Node
uses: actions/setup-node@v3
@ -137,7 +137,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: "Test server (minimum): ${{matrix['db']}}"
run: cd focalboard; make server-test-mini-${{matrix['db']}}
@ -174,7 +174,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: "Test server (minimum): ${{matrix['db']}}"
run: cd focalboard; make server-test-mini-${{matrix['db']}}

@ -54,7 +54,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Setup Node
uses: actions/setup-node@v3
@ -129,7 +129,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: List Xcode versions
run: ls -n /Applications/ | grep Xcode*
@ -190,7 +190,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Setup NuGet
uses: nuget/setup-nuget@v1
@ -258,7 +258,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Set up Node
uses: actions/setup-node@v3

@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- uses: actions/checkout@v3
with:
path: "focalboard"
@ -50,7 +50,7 @@ jobs:
path: "mattermost-server"
ref : "master"
- name: set up golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1
- name: lint
run: |
cd focalboard

@ -50,7 +50,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Setup Node
uses: actions/setup-node@v3
@ -126,7 +126,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: List Xcode versions
run: ls -n /Applications/ | grep Xcode*
@ -188,7 +188,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Setup NuGet
uses: nuget/setup-nuget@v1
@ -257,7 +257,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.19.5
- name: Set up Node
uses: actions/setup-node@v3

@ -4,7 +4,7 @@ stages:
variables:
BUILD: "yes"
IMAGE_BUILDER: $CI_REGISTRY/mattermost/ci/images/builder:go-1.18.1-node-16.15.0-1
IMAGE_BUILDER: $CI_REGISTRY/mattermost/ci/images/builder:go-1.19.5-node-16.15.0-1
include:
- project: mattermost/ci/focalboard

@ -51,7 +51,7 @@ func makeGoWork(ci bool) string {
var b strings.Builder
b.WriteString("go 1.18\n\n")
b.WriteString("go 1.19\n\n")
b.WriteString("use ./server\n")
for repo, envVarName := range repos {

@ -1,6 +1,6 @@
module github.com/mattermost/focalboard/linux
go 1.18
go 1.19
replace github.com/mattermost/focalboard/server => ../server

@ -1,6 +1,6 @@
module github.com/mattermost/mattermost-plugin-starter-template/build
go 1.18
go 1.19
require (
github.com/go-git/go-git/v5 v5.1.0

@ -1,6 +1,6 @@
module github.com/mattermost/focalboard/mattermost-plugin
go 1.18
go 1.19
require (
github.com/golang/mock v1.6.0

@ -27,10 +27,7 @@ linters:
enable:
- gofmt
- goimports
- deadcode
- ineffassign
- structcheck
- varcheck
- unparam
- errcheck
- govet

@ -220,7 +220,7 @@ func stringResponse(w http.ResponseWriter, message string) {
_, _ = fmt.Fprint(w, message)
}
func jsonStringResponse(w http.ResponseWriter, code int, message string) {
func jsonStringResponse(w http.ResponseWriter, code int, message string) { //nolint:unparam
setResponseHeader(w, "Content-Type", "application/json")
w.WriteHeader(code)
fmt.Fprint(w, message)
@ -232,7 +232,7 @@ func jsonBytesResponse(w http.ResponseWriter, code int, json []byte) {
_, _ = w.Write(json)
}
func setResponseHeader(w http.ResponseWriter, key string, value string) {
func setResponseHeader(w http.ResponseWriter, key string, value string) { //nolint:unparam
header := w.Header()
if header == nil {
return

@ -8,7 +8,7 @@ import (
)
// makeAuditRecord creates an audit record pre-populated with data from the request.
func (a *API) makeAuditRecord(r *http.Request, event string, initialStatus string) *audit.Record {
func (a *API) makeAuditRecord(r *http.Request, event string, initialStatus string) *audit.Record { //nolint:unparam
ctx := r.Context()
var sessionID string
var userID string

@ -383,12 +383,13 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
authService := session.AuthService
if authService != a.authService {
a.logger.Error(`Session authService mismatch`,
msg := `Session authService mismatch`
a.logger.Error(msg,
mlog.String("sessionID", session.ID),
mlog.String("want", a.authService),
mlog.String("got", authService),
)
a.errorResponse(w, r, model.NewErrUnauthorized(err.Error()))
a.errorResponse(w, r, model.NewErrUnauthorized(msg))
return
}

@ -146,7 +146,7 @@ func (a *API) handleAddMember(w http.ResponseWriter, r *http.Request) {
}
if reqBoardMember.UserID == "" {
a.errorResponse(w, r, model.NewErrBadRequest(err.Error()))
a.errorResponse(w, r, model.NewErrBadRequest("empty userID"))
return
}

@ -19,7 +19,7 @@ func (a *App) GetTeamBoardsInsights(userID string, teamID string, opts *mmModel.
if err != nil {
return nil, err
}
return a.store.GetTeamBoardsInsights(teamID, userID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage, boardIDs)
return a.store.GetTeamBoardsInsights(teamID, opts.StartUnixMilli, opts.Page*opts.PerPage, opts.PerPage, boardIDs)
}
func (a *App) GetUserBoardsInsights(userID string, teamID string, opts *mmModel.InsightsOpts) (*model.BoardInsightsList, error) {

@ -51,7 +51,7 @@ func TestGetTeamAndUserBoardsInsights(t *testing.T) {
th.Store.EXPECT().GetUserByID("user-id").Return(fakeUser, nil).AnyTimes()
th.Store.EXPECT().GetBoardsForUserAndTeam("user-id", "team-id", true).Return(mockInsightsBoards, nil).AnyTimes()
th.Store.EXPECT().
GetTeamBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
GetTeamBoardsInsights("team-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
Return(mockTeamInsightsList, nil)
results, err := th.App.GetTeamBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
require.NoError(t, err)
@ -74,7 +74,7 @@ func TestGetTeamAndUserBoardsInsights(t *testing.T) {
th.Store.EXPECT().GetUserByID("user-id").Return(fakeUser, nil).AnyTimes()
th.Store.EXPECT().GetBoardsForUserAndTeam("user-id", "team-id", true).Return(mockInsightsBoards, nil).AnyTimes()
th.Store.EXPECT().
GetTeamBoardsInsights("team-id", "user-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
GetTeamBoardsInsights("team-id", int64(0), 0, 10, []string{"mock-user-workspace-id"}).
Return(nil, insightError{"board-insight-error"})
_, err := th.App.GetTeamBoardsInsights("user-id", "team-id", &mmModel.InsightsOpts{StartUnixMilli: 0, Page: 0, PerPage: 10})
require.Error(t, err)

@ -7,5 +7,6 @@ import (
// DefaultTemplatesArchive is an embedded archive file containing the default
// templates to be imported to team 0.
// This archive is generated with `make templates-archive`
//
//go:embed templates.boardarchive
var DefaultTemplatesArchive []byte

@ -1,6 +1,6 @@
module github.com/mattermost/focalboard/server
go 1.18
go 1.19
require (
github.com/Masterminds/squirrel v1.5.3

@ -1,6 +1,6 @@
module github.com/mattermost/focalboard/server
go 1.18
go 1.19
require github.com/golang/mock v1.6.0

@ -269,9 +269,7 @@ func TestGetCard(t *testing.T) {
})
}
//
// Helpers.
//
func reverse(src []string) []string {
out := make([]string, 0, len(src))
for i := len(src) - 1; i >= 0; i-- {

@ -122,7 +122,7 @@ func main() {
if pDBConfig != nil && len(*pDBConfig) > 0 {
config.DBConfigString = *pDBConfig
// Don't echo, as the confix string may contain passwords
logger.Info("DBConfigString overriden from commandline")
logger.Info("DBConfigString overridden from commandline")
}
if pPort != nil && *pPort > 0 && *pPort != config.Port {
@ -166,6 +166,7 @@ func main() {
}
// StartServer starts the server
//
//export StartServer
func StartServer(webPath *C.char, filesPath *C.char, port int, singleUserToken, dbConfigString, configFilePath *C.char) {
startServer(
@ -179,6 +180,7 @@ func StartServer(webPath *C.char, filesPath *C.char, port int, singleUserToken,
}
// StopServer stops the server
//
//export StopServer
func StopServer() {
stopServer()

@ -377,7 +377,7 @@ func (s *Server) UpdateAppConfig() {
// Local server
func (s *Server) startLocalModeServer() error {
s.localModeServer = &http.Server{
s.localModeServer = &http.Server{ //nolint:gosec
Handler: s.localRouter,
ConnContext: api.SetContextConn,
}

@ -46,12 +46,14 @@ func NewAudit(options ...mlog.Option) (*Audit, error) {
// Configure provides a new configuration for this audit service.
// Zero or more sources of config can be provided:
// cfgFile - path to file containing JSON
// cfgEscaped - JSON string probably from ENV var
//
// cfgFile - path to file containing JSON
// cfgEscaped - JSON string probably from ENV var
//
// For each case JSON containing log targets is provided. Target name collisions are resolved
// using the following precedence:
// cfgFile > cfgEscaped
//
// cfgFile > cfgEscaped
func (a *Audit) Configure(cfgFile string, cfgEscaped string) error {
return a.auditLogger.Configure(cfgFile, cfgEscaped, nil)
}

@ -17,7 +17,7 @@ type Service struct {
// NewMetricsServer factory method to create a new prometheus server.
func NewMetricsServer(address string, metricsService *Metrics, logger mlog.LoggerIFace) *Service {
return &Service{
&http.Server{
&http.Server{ //nolint:gosec
Addr: address,
Handler: promhttp.HandlerFor(metricsService.registry, promhttp.HandlerOpts{
ErrorLog: logger.StdLogger(mlog.LvlError),

@ -599,7 +599,7 @@ func (s *MattermostAuthLayer) GetLicense() *mmModel.License {
return s.servicesAPI.GetLicense()
}
func boardFields(prefix string) []string {
func boardFields(prefix string) []string { //nolint:unparam
fields := []string{
"id",
"team_id",

@ -999,18 +999,18 @@ func (mr *MockStoreMockRecorder) GetTeam(arg0 interface{}) *gomock.Call {
}
// GetTeamBoardsInsights mocks base method.
func (m *MockStore) GetTeamBoardsInsights(arg0, arg1 string, arg2 int64, arg3, arg4 int, arg5 []string) (*model.BoardInsightsList, error) {
func (m *MockStore) GetTeamBoardsInsights(arg0 string, arg1 int64, arg2, arg3 int, arg4 []string) (*model.BoardInsightsList, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTeamBoardsInsights", arg0, arg1, arg2, arg3, arg4, arg5)
ret := m.ctrl.Call(m, "GetTeamBoardsInsights", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(*model.BoardInsightsList)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetTeamBoardsInsights indicates an expected call of GetTeamBoardsInsights.
func (mr *MockStoreMockRecorder) GetTeamBoardsInsights(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
func (mr *MockStoreMockRecorder) GetTeamBoardsInsights(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTeamBoardsInsights", reflect.TypeOf((*MockStore)(nil).GetTeamBoardsInsights), arg0, arg1, arg2, arg3, arg4, arg5)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTeamBoardsInsights", reflect.TypeOf((*MockStore)(nil).GetTeamBoardsInsights), arg0, arg1, arg2, arg3, arg4)
}
// GetTeamCount mocks base method.

@ -14,7 +14,7 @@ import (
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
func (s *SQLStore) getTeamBoardsInsights(db sq.BaseRunner, teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
func (s *SQLStore) getTeamBoardsInsights(db sq.BaseRunner, teamID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
boardsHistoryQuery := s.getQueryBuilder(db).
Select("boards.id, boards.icon, boards.title, count(boards_history.id) as count, boards_history.modified_by, boards.created_by").
From(s.tablePrefix + "boards_history as boards_history").

@ -144,7 +144,7 @@ func (s *SQLStore) CreateUser(user *model.User) (*model.User, error) {
}
func (s *SQLStore) DBVersion() string {
return s.dBVersion(s.db)
return s.dBVersion()
}
@ -513,8 +513,8 @@ func (s *SQLStore) GetTeam(ID string) (*model.Team, error) {
}
func (s *SQLStore) GetTeamBoardsInsights(teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
return s.getTeamBoardsInsights(s.db, teamID, userID, since, offset, limit, boardIDs)
func (s *SQLStore) GetTeamBoardsInsights(teamID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error) {
return s.getTeamBoardsInsights(s.db, teamID, since, offset, limit, boardIDs)
}

@ -136,7 +136,7 @@ func (s *SQLStore) getQueryBuilder(db sq.BaseRunner) sq.StatementBuilderType {
return builder.RunWith(db)
}
func (s *SQLStore) escapeField(fieldName string) string {
func (s *SQLStore) escapeField(fieldName string) string { //nolint:unparam
if s.dbType == model.MysqlDBType {
return "`" + fieldName + "`"
}
@ -185,7 +185,7 @@ func (s *SQLStore) getChannel(db sq.BaseRunner, teamID, channel string) (*mmMode
return nil, store.NewNotSupportedError("get channel not supported on standalone mode")
}
func (s *SQLStore) dBVersion(db sq.BaseRunner) string {
func (s *SQLStore) dBVersion() string {
var version string
var row *sql.Row

@ -168,7 +168,7 @@ type Store interface {
SendMessage(message, postType string, receipts []string) error
// Insights
GetTeamBoardsInsights(teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error)
GetTeamBoardsInsights(teamID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error)
GetUserBoardsInsights(teamID string, userID string, since int64, offset int, limit int, boardIDs []string) (*model.BoardInsightsList, error)
GetUserTimezone(userID string) (string, error)

@ -72,7 +72,7 @@ func getBoardsInsightsTest(t *testing.T, store store.Store) {
boardsUser2, _ := store.GetBoardsForUserAndTeam(testInsightsUserID1, testTeamID, true)
t.Run("team insights", func(t *testing.T) {
boardIDs := []string{boardsUser1[0].ID, boardsUser1[1].ID, boardsUser1[2].ID}
topTeamBoards, err := store.GetTeamBoardsInsights(testTeamID, testUserID,
topTeamBoards, err := store.GetTeamBoardsInsights(testTeamID,
0, 0, 10, boardIDs)
require.NoError(t, err)
require.Len(t, topTeamBoards.Items, 3)

@ -59,7 +59,8 @@ func NewServer(rootPath string, serverRoot string, port int, ssl, localOnly bool
baseURL = url.Path
ws := &Server{
Server: http.Server{
// (TODO: Add ReadHeaderTimeout)
Server: http.Server{ //nolint:gosec
Addr: addr,
Handler: r,
},

@ -422,7 +422,7 @@ func (pa *PluginAdapter) sendTeamMessage(event, teamID string, payload map[strin
EnsureUsers: ensureUserIDs,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendTeamMessageSkipCluster(event, teamID, payload)
@ -447,7 +447,7 @@ func (pa *PluginAdapter) sendBoardMessage(teamID, boardID string, payload map[st
EnsureUsers: ensureUserIDs,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendBoardMessageSkipCluster(teamID, boardID, payload, ensureUserIDs...)
@ -490,7 +490,7 @@ func (pa *PluginAdapter) BroadcastCategoryChange(category model.Category) {
UserID: category.UserID,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendUserMessageSkipCluster(websocketActionUpdateCategory, payload, category.UserID)
@ -514,7 +514,7 @@ func (pa *PluginAdapter) BroadcastCategoryReorder(teamID, userID string, categor
UserID: userID,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendUserMessageSkipCluster(message.Action, payload, userID)
@ -540,7 +540,7 @@ func (pa *PluginAdapter) BroadcastCategoryBoardsReorder(teamID, userID, category
UserID: userID,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendUserMessageSkipCluster(message.Action, payload, userID)
@ -568,7 +568,7 @@ func (pa *PluginAdapter) BroadcastCategoryBoardChange(teamID, userID string, boa
UserID: userID,
}
pa.sendMessageToCluster("websocket_message", clusterMessage)
pa.sendMessageToCluster(clusterMessage)
}()
pa.sendUserMessageSkipCluster(websocketActionUpdateCategoryBoard, utils.StructToMap(message), userID)

@ -15,7 +15,8 @@ type ClusterMessage struct {
EnsureUsers []string
}
func (pa *PluginAdapter) sendMessageToCluster(id string, clusterMessage *ClusterMessage) {
func (pa *PluginAdapter) sendMessageToCluster(clusterMessage *ClusterMessage) {
const id = "websocket_message"
b, err := json.Marshal(clusterMessage)
if err != nil {
pa.logger.Error("couldn't get JSON bytes from cluster message",

Loading…
Cancel
Save