From 4d05492f43e9e471b3c3e82c49469de1a3359bd9 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 20 Sep 2017 12:08:24 +0100 Subject: [PATCH 1/6] use matching sytest branch, or develop --- jenkins/test-monolith.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jenkins/test-monolith.sh b/jenkins/test-monolith.sh index 344fdd3aa..538447c1d 100755 --- a/jenkins/test-monolith.sh +++ b/jenkins/test-monolith.sh @@ -13,12 +13,21 @@ rm -f sytest/server-*/*.log sytest/results.tap ./jenkins/prepare-dendrite.sh if [ ! -d "sytest" ]; then - git clone https://github.com/matrix-org/sytest.git --depth 1 --branch dendrite -else - git -C sytest fetch --depth 1 origin dendrite - git -C sytest reset --hard FETCH_HEAD + git clone https://github.com/matrix-org/sytest.git --depth 1 --branch master fi +# Jenkins may have supplied us with the name of the branch in the +# environment. Otherwise we will have to guess based on the current +# commit. +: ${GIT_BRANCH:="origin/$(git rev-parse --abbrev-ref HEAD)"} + +git -C sytest fetch --depth 1 origin "${GIT_BRANCH}" || { + echo >&2 "No ref ${GIT_BRANCH} found, falling back to develop" + git -C sytest fetch --depth 1 origin develop +} + +git -C sytest reset --hard FETCH_HEAD + ./sytest/jenkins/prep_sytest_for_postgres.sh ./sytest/jenkins/install_and_run.sh \ From b72142ace5a395b32563f79babc26e46b4586cf8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 13:40:22 +0100 Subject: [PATCH 2/6] Add vet linter (#240) --- linter-fast.json | 3 ++- linter.json | 3 ++- .../dendrite/clientapi/writers/createroom.go | 10 ++++---- .../dendrite-federation-api-server/main.go | 2 +- .../dendrite/common/config/config.go | 2 +- .../dendrite/common/keydb/server_key_table.go | 3 ++- .../dendrite/federationapi/readers/keys.go | 2 +- .../roomserver/input/authevents_test.go | 25 +++++++++++-------- .../dendrite/roomserver/state/state_test.go | 17 +++++++------ 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/linter-fast.json b/linter-fast.json index 2abb30aff..fce445f20 100644 --- a/linter-fast.json +++ b/linter-fast.json @@ -10,6 +10,7 @@ "ineffassign", "gas", "misspell", - "errcheck" + "errcheck", + "vet" ] } diff --git a/linter.json b/linter.json index 649e6a0e5..f8da97782 100644 --- a/linter.json +++ b/linter.json @@ -15,6 +15,7 @@ "gas", "misspell", "unparam", - "errcheck" + "errcheck", + "vet" ] } diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go b/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go index 7d5d318db..99ba2ebdb 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go @@ -163,12 +163,12 @@ func createRoom(req *http.Request, device *authtypes.Device, {"m.room.member", userID, membershipContent}, {"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)}, // TODO: m.room.canonical_alias - {"m.room.join_rules", "", common.JoinRulesContent{"public"}}, // FIXME: Allow this to be changed - {"m.room.history_visibility", "", common.HistoryVisibilityContent{"joined"}}, // FIXME: Allow this to be changed - {"m.room.guest_access", "", common.GuestAccessContent{"can_join"}}, // FIXME: Allow this to be changed + {"m.room.join_rules", "", common.JoinRulesContent{JoinRule: "public"}}, // FIXME: Allow this to be changed + {"m.room.history_visibility", "", common.HistoryVisibilityContent{HistoryVisibility: "joined"}}, // FIXME: Allow this to be changed + {"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}}, // FIXME: Allow this to be changed // TODO: Other initial state items - {"m.room.name", "", common.NameContent{r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event - {"m.room.topic", "", common.TopicContent{r.Topic}}, + {"m.room.name", "", common.NameContent{Name: r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event + {"m.room.topic", "", common.TopicContent{Topic: r.Topic}}, // TODO: invite events // TODO: 3pid invite events // TODO: m.room.aliases diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go index 151a7a9f4..b287ea629 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go @@ -67,7 +67,7 @@ func main() { keyRing := gomatrixserverlib.KeyRing{ KeyFetchers: []gomatrixserverlib.KeyFetcher{ // TODO: Use perspective key fetchers for production. - &gomatrixserverlib.DirectKeyFetcher{federation.Client}, + &gomatrixserverlib.DirectKeyFetcher{Client: federation.Client}, }, KeyDatabase: keyDB, } diff --git a/src/github.com/matrix-org/dendrite/common/config/config.go b/src/github.com/matrix-org/dendrite/common/config/config.go index 86234b8da..019774b45 100644 --- a/src/github.com/matrix-org/dendrite/common/config/config.go +++ b/src/github.com/matrix-org/dendrite/common/config/config.go @@ -413,7 +413,7 @@ func fingerprintPEM(data []byte) *gomatrixserverlib.TLSFingerprint { } if certDERBlock.Type == "CERTIFICATE" { digest := sha256.Sum256(certDERBlock.Bytes) - return &gomatrixserverlib.TLSFingerprint{digest[:]} + return &gomatrixserverlib.TLSFingerprint{SHA256: digest[:]} } } } diff --git a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go index a459bd8c3..b1d6d65f5 100644 --- a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go +++ b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go @@ -97,7 +97,8 @@ func (s *serverKeyStatements) bulkSelectServerKeys( return nil, err } r := gomatrixserverlib.PublicKeyRequest{ - gomatrixserverlib.ServerName(serverName), gomatrixserverlib.KeyID(keyID), + ServerName: gomatrixserverlib.ServerName(serverName), + KeyID: gomatrixserverlib.KeyID(keyID), } results[r] = serverKeys } diff --git a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go index fcca201e6..b28bdec99 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go +++ b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go @@ -44,7 +44,7 @@ func localKeys(cfg config.Dendrite, validUntil time.Time) (*gomatrixserverlib.Se keys.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{ cfg.Matrix.KeyID: { - gomatrixserverlib.Base64String(publicKey), + Key: gomatrixserverlib.Base64String(publicKey), }, } diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go b/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go index 3e4d194ba..0621a0842 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go @@ -15,24 +15,29 @@ package input import ( - "github.com/matrix-org/dendrite/roomserver/types" "testing" + + "github.com/matrix-org/dendrite/roomserver/types" ) func benchmarkStateEntryMapLookup(entries, lookups int64, b *testing.B) { var list []types.StateEntry for i := int64(0); i < entries; i++ { - list = append(list, types.StateEntry{types.StateKeyTuple{ - types.EventTypeNID(i), - types.EventStateKeyNID(i), - }, types.EventNID(i)}) + list = append(list, types.StateEntry{ + StateKeyTuple: types.StateKeyTuple{ + EventTypeNID: types.EventTypeNID(i), + EventStateKeyNID: types.EventStateKeyNID(i), + }, + EventNID: types.EventNID(i), + }) } for i := 0; i < b.N; i++ { entryMap := stateEntryMap(list) for j := int64(0); j < lookups; j++ { entryMap.lookup(types.StateKeyTuple{ - types.EventTypeNID(j), types.EventStateKeyNID(j), + EventTypeNID: types.EventTypeNID(j), + EventStateKeyNID: types.EventStateKeyNID(j), }) } } @@ -56,9 +61,9 @@ func BenchmarkStateEntryMap1000Lookup10000(b *testing.B) { func TestStateEntryMap(t *testing.T) { entryMap := stateEntryMap([]types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 3}, 2}, - {types.StateKeyTuple{2, 1}, 3}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 3}, EventNID: 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 1}, EventNID: 3}, }) testCases := []struct { @@ -78,7 +83,7 @@ func TestStateEntryMap(t *testing.T) { } for _, testCase := range testCases { - keyTuple := types.StateKeyTuple{testCase.inputTypeNID, testCase.inputStateKey} + keyTuple := types.StateKeyTuple{EventTypeNID: testCase.inputTypeNID, EventStateKeyNID: testCase.inputStateKey} gotEventNID, gotOK := entryMap.lookup(keyTuple) if testCase.wantOK != gotOK { t.Fatalf("stateEntryMap lookup(%v): want ok to be %v, got %v", keyTuple, testCase.wantOK, gotOK) diff --git a/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go b/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go index 78d29f78d..67af18671 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go +++ b/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go @@ -15,8 +15,9 @@ package state import ( - "github.com/matrix-org/dendrite/roomserver/types" "testing" + + "github.com/matrix-org/dendrite/roomserver/types" ) func TestFindDuplicateStateKeys(t *testing.T) { @@ -25,18 +26,18 @@ func TestFindDuplicateStateKeys(t *testing.T) { Want []types.StateEntry }{{ Input: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 1}, 2}, - {types.StateKeyTuple{2, 2}, 3}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 2}, EventNID: 3}, }, Want: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 1}, 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2}, }, }, { Input: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 2}, 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 2}, EventNID: 2}, }, Want: nil, }} From cc2f755cb38a2277c00c8ce1d42b188910c21caf Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 14:15:38 +0100 Subject: [PATCH 3/6] Add gosimple linter (#242) --- linter.json | 3 ++- .../clientapi/auth/storage/devices/storage.go | 5 +---- .../dendrite/clientapi/producers/syncapi.go | 7 ++----- .../dendrite/clientapi/producers/userupdate.go | 7 ++----- .../dendrite/common/keydb/server_key_table.go | 5 +---- .../matrix-org/dendrite/common/test/config.go | 18 ++++++------------ .../dendrite/federationapi/writers/threepid.go | 6 +----- .../dendrite/mediaapi/fileutils/fileutils.go | 2 +- .../mediaapi/thumbnailer/thumbnailer.go | 6 +----- .../mediaapi/thumbnailer/thumbnailer_nfnt.go | 2 +- .../dendrite/mediaapi/writers/download.go | 6 +++--- .../dendrite/mediaapi/writers/upload.go | 2 +- .../publicroomsapi/directory/public_rooms.go | 5 +---- .../dendrite/roomserver/alias/alias.go | 6 +----- .../dendrite/roomserver/input/latest_events.go | 10 +++------- .../dendrite/syncapi/storage/syncserver.go | 4 +--- 16 files changed, 28 insertions(+), 66 deletions(-) diff --git a/linter.json b/linter.json index f8da97782..fb30f2288 100644 --- a/linter.json +++ b/linter.json @@ -16,6 +16,7 @@ "misspell", "unparam", "errcheck", - "vet" + "vet", + "gosimple" ] } diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go index 6b7ff919d..df8bf4f3f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go @@ -67,10 +67,7 @@ func (d *Database) CreateDevice( } dev, err = d.devices.insertDevice(ctx, txn, deviceID, localpart, accessToken) - if err != nil { - return err - } - return nil + return err }) return } diff --git a/src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go b/src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go index dba104f90..6bfcd51aa 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go +++ b/src/github.com/matrix-org/dendrite/clientapi/producers/syncapi.go @@ -45,9 +45,6 @@ func (p *SyncAPIProducer) SendData(userID string, roomID string, dataType string m.Key = sarama.StringEncoder(userID) m.Value = sarama.ByteEncoder(value) - if _, _, err := p.Producer.SendMessage(&m); err != nil { - return err - } - - return nil + _, _, err = p.Producer.SendMessage(&m) + return err } diff --git a/src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go b/src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go index 2f2ed7565..2a5dfc70a 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go +++ b/src/github.com/matrix-org/dendrite/clientapi/producers/userupdate.go @@ -57,9 +57,6 @@ func (p *UserUpdateProducer) SendUpdate( } m.Value = sarama.ByteEncoder(value) - if _, _, err := p.Producer.SendMessage(&m); err != nil { - return err - } - - return nil + _, _, err = p.Producer.SendMessage(&m) + return err } diff --git a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go index b1d6d65f5..e89ebcda3 100644 --- a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go +++ b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go @@ -116,10 +116,7 @@ func (s *serverKeyStatements) upsertServerKeys( string(request.ServerName), string(request.KeyID), nameAndKeyID(request), int64(keys.ValidUntilTS), keyJSON, ) - if err != nil { - return err - } - return nil + return err } func nameAndKeyID(request gomatrixserverlib.PublicKeyRequest) string { diff --git a/src/github.com/matrix-org/dendrite/common/test/config.go b/src/github.com/matrix-org/dendrite/common/test/config.go index d29b754ea..ad878c5b8 100644 --- a/src/github.com/matrix-org/dendrite/common/test/config.go +++ b/src/github.com/matrix-org/dendrite/common/test/config.go @@ -135,17 +135,14 @@ func NewMatrixKey(matrixKeyPath string) (err error) { err = keyOut.Close() })() - if err = pem.Encode(keyOut, &pem.Block{ + err = pem.Encode(keyOut, &pem.Block{ Type: "MATRIX PRIVATE KEY", Headers: map[string]string{ "Key-ID": "ed25519:" + base64.RawStdEncoding.EncodeToString(data[:3]), }, Bytes: data[3:], - }); err != nil { - return err - } - - return nil + }) + return err } const certificateDuration = time.Hour * 24 * 365 * 10 @@ -191,12 +188,9 @@ func NewTLSKey(tlsKeyPath, tlsCertPath string) error { return err } defer keyOut.Close() // nolint: errcheck - if err = pem.Encode(keyOut, &pem.Block{ + err = pem.Encode(keyOut, &pem.Block{ Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv), - }); err != nil { - return err - } - - return nil + }) + return err } diff --git a/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go b/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go index 1ab03a341..7c4ccfcff 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go +++ b/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go @@ -347,9 +347,5 @@ func fillDisplayName( // Use the m.room.third_party_invite event to fill the "displayname" and // update the m.room.member event's content with it content.ThirdPartyInvite.DisplayName = thirdPartyInviteContent.DisplayName - if err := builder.SetContent(content); err != nil { - return err - } - - return nil + return builder.SetContent(content) } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go index e9a1a5193..97e5fe999 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go @@ -55,7 +55,7 @@ func GetPathFromBase64Hash(base64Hash types.Base64Hash, absBasePath config.Path) // check if the absolute absBasePath is a prefix of the absolute filePath // if so, no directory escape has occurred and the filePath is valid // Note: absBasePath is already absolute - if strings.HasPrefix(filePath, string(absBasePath)) == false { + if !strings.HasPrefix(filePath, string(absBasePath)) { return "", fmt.Errorf("Invalid filePath (not within absBasePath %v): %v", absBasePath, filePath) } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go index ded71b651..6aa76cf0f 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go @@ -80,11 +80,7 @@ func SelectThumbnail(desired types.ThumbnailSize, thumbnails []*types.ThumbnailM fitness := calcThumbnailFitness(types.ThumbnailSize(thumbnailSize), nil, desired) if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter { bestFit = fitness - chosenThumbnailSize = &types.ThumbnailSize{ - Width: thumbnailSize.Width, - Height: thumbnailSize.Height, - ResizeMethod: thumbnailSize.ResizeMethod, - } + chosenThumbnailSize = (*types.ThumbnailSize)(&thumbnailSize) } } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go index 06607f719..a55a6d2a8 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go @@ -156,7 +156,7 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize logger.WithFields(log.Fields{ "ActualWidth": width, "ActualHeight": height, - "processTime": time.Now().Sub(start), + "processTime": time.Since(start), }).Info("Generated thumbnail") stat, err := os.Stat(string(dst)) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go index 490685809..c69f5ae90 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -155,7 +155,7 @@ func (r *downloadRequest) jsonErrorResponse(w http.ResponseWriter, res util.JSON // Validate validates the downloadRequest fields func (r *downloadRequest) Validate() *util.JSONResponse { - if mediaIDRegex.MatchString(string(r.MediaMetadata.MediaID)) == false { + if !mediaIDRegex.MatchString(string(r.MediaMetadata.MediaID)) { return &util.JSONResponse{ Code: 404, JSON: jsonerror.NotFound(fmt.Sprintf("mediaId must be a non-empty string using only characters in %v", mediaIDCharacters)), @@ -337,7 +337,7 @@ func (r *downloadRequest) getThumbnailFile( thumbnail, thumbnailSize = thumbnailer.SelectThumbnail(r.ThumbnailSize, thumbnails, thumbnailSizes) // If dynamicThumbnails is true and we are not over-loaded then we would have generated what was requested above. // So we don't try to generate a pre-generated thumbnail here. - if thumbnailSize != nil && dynamicThumbnails == false { + if thumbnailSize != nil && !dynamicThumbnails { r.Logger.WithFields(log.Fields{ "Width": thumbnailSize.Width, "Height": thumbnailSize.Height, @@ -525,7 +525,7 @@ func (r *downloadRequest) fetchRemoteFileAndStoreMetadata( // If the file is a duplicate (has the same hash as an existing file) then // there is valid metadata in the database for that file. As such we only // remove the file if it is not a duplicate. - if duplicate == false { + if !duplicate { finalDir := filepath.Dir(string(finalPath)) fileutils.RemoveDir(types.Path(finalDir), r.Logger) } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go index eaea8561e..f7ffd3683 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go @@ -226,7 +226,7 @@ func (r *uploadRequest) storeFileAndMetadata(tmpDir types.Path, absBasePath conf // If the file is a duplicate (has the same hash as an existing file) then // there is valid metadata in the database for that file. As such we only // remove the file if it is not a duplicate. - if duplicate == false { + if !duplicate { fileutils.RemoveDir(types.Path(path.Dir(string(finalPath))), r.Logger) } return &util.JSONResponse{ diff --git a/src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go b/src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go index 19ae90d8d..772c0f6bf 100644 --- a/src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go +++ b/src/github.com/matrix-org/dendrite/publicroomsapi/directory/public_rooms.go @@ -102,10 +102,7 @@ func fillPublicRoomsReq(httpReq *http.Request, request *publicRoomReq) *util.JSO request.Since = httpReq.FormValue("since") return nil } else if httpReq.Method == "POST" { - if reqErr := httputil.UnmarshalJSONRequest(httpReq, request); reqErr != nil { - return reqErr - } - return nil + return httputil.UnmarshalJSONRequest(httpReq, request) } return &util.JSONResponse{ diff --git a/src/github.com/matrix-org/dendrite/roomserver/alias/alias.go b/src/github.com/matrix-org/dendrite/roomserver/alias/alias.go index 91aa3a262..fed98dd82 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/alias/alias.go +++ b/src/github.com/matrix-org/dendrite/roomserver/alias/alias.go @@ -217,11 +217,7 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent( var inputRes api.InputRoomEventsResponse // Send the request - if err := r.InputAPI.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil { - return err - } - - return nil + return r.InputAPI.InputRoomEvents(ctx, &inputReq, &inputRes) } // SetupHTTP adds the RoomserverAliasAPI handlers to the http.ServeMux. diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go b/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go index c20613db7..30129a626 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go @@ -102,8 +102,7 @@ type latestEventsUpdater struct { } func (u *latestEventsUpdater) doUpdateLatestEvents() error { - var prevEvents []gomatrixserverlib.EventReference - prevEvents = u.event.PrevEvents() + prevEvents := u.event.PrevEvents() oldLatest := u.updater.LatestEvents() u.lastEventIDSent = u.updater.LastEventIDSent() u.oldStateNID = u.updater.CurrentStateSnapshotNID() @@ -194,10 +193,7 @@ func (u *latestEventsUpdater) latestState() error { u.stateBeforeEventRemoves, u.stateBeforeEventAdds, err = state.DifferenceBetweeenStateSnapshots( u.ctx, u.db, u.newStateNID, u.stateAtEvent.BeforeStateSnapshotNID, ) - if err != nil { - return err - } - return nil + return err } func calculateLatest( @@ -211,7 +207,7 @@ func calculateLatest( for _, l := range oldLatest { keep := true for _, prevEvent := range prevEvents { - if l.EventID == prevEvent.EventID && bytes.Compare(l.EventSHA256, prevEvent.EventSHA256) == 0 { + if l.EventID == prevEvent.EventID && bytes.Equal(l.EventSHA256, prevEvent.EventSHA256) { // This event can be removed from the latest events cause we've found an event that references it. // (If an event is referenced by another event then it can't be one of the latest events in the room // because we have an event that comes after it) diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go index a26b14c0e..e65639eb7 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/syncserver.go @@ -461,9 +461,7 @@ func (d *SyncServerDatabase) fetchMissingStateEvents( if len(stateEvents) != len(missing) { return nil, fmt.Errorf("failed to map all event IDs to events: (got %d, wanted %d)", len(stateEvents), len(missing)) } - for _, e := range stateEvents { - events = append(events, e) - } + events = append(events, stateEvents...) return events, nil } From 584acbe9a91cad44b46afebff0cc7eb1302efed1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 14:47:29 +0100 Subject: [PATCH 4/6] Add 'unused' lint (#241) * Add 'unused' lint * Keep testdata consts --- linter.json | 1 + .../auth/storage/accounts/membership_table.go | 16 ---------------- .../cmd/syncserver-integration-tests/testdata.go | 2 +- .../dendrite/common/partition_offset_table.go | 1 + .../publicroomsapi/storage/public_rooms_table.go | 1 + .../roomserver/storage/event_state_keys_table.go | 15 --------------- .../dendrite/roomserver/storage/prepare.go | 1 + 7 files changed, 5 insertions(+), 32 deletions(-) diff --git a/linter.json b/linter.json index fb30f2288..5fff55980 100644 --- a/linter.json +++ b/linter.json @@ -17,6 +17,7 @@ "unparam", "errcheck", "vet", + "unused", "gosimple" ] } diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/membership_table.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/membership_table.go index 11cecb8b6..1a0d0fedf 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/membership_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/membership_table.go @@ -51,14 +51,10 @@ const selectMembershipsByLocalpartSQL = "" + const deleteMembershipsByEventIDsSQL = "" + "DELETE FROM account_memberships WHERE event_id = ANY($1)" -const updateMembershipByEventIDSQL = "" + - "UPDATE account_memberships SET event_id = $2 WHERE event_id = $1" - type membershipStatements struct { deleteMembershipsByEventIDsStmt *sql.Stmt insertMembershipStmt *sql.Stmt selectMembershipsByLocalpartStmt *sql.Stmt - updateMembershipByEventIDStmt *sql.Stmt } func (s *membershipStatements) prepare(db *sql.DB) (err error) { @@ -75,9 +71,6 @@ func (s *membershipStatements) prepare(db *sql.DB) (err error) { if s.selectMembershipsByLocalpartStmt, err = db.Prepare(selectMembershipsByLocalpartSQL); err != nil { return } - if s.updateMembershipByEventIDStmt, err = db.Prepare(updateMembershipByEventIDSQL); err != nil { - return - } return } @@ -120,12 +113,3 @@ func (s *membershipStatements) selectMembershipsByLocalpart( return } - -func (s *membershipStatements) updateMembershipByEventID( - ctx context.Context, oldEventID string, newEventID string, -) (err error) { - _, err = s.updateMembershipByEventIDStmt.ExecContext( - ctx, oldEventID, newEventID, - ) - return -} diff --git a/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go b/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go index dfbcc6a5d..bde34ae79 100644 --- a/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go +++ b/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go @@ -14,7 +14,7 @@ package main -// nolint: varcheck, deadcode +// nolint: varcheck, deadcode, unused const ( i0StateRoomCreate = iota i1StateAliceJoin diff --git a/src/github.com/matrix-org/dendrite/common/partition_offset_table.go b/src/github.com/matrix-org/dendrite/common/partition_offset_table.go index 63aa61a57..9d727c56e 100644 --- a/src/github.com/matrix-org/dendrite/common/partition_offset_table.go +++ b/src/github.com/matrix-org/dendrite/common/partition_offset_table.go @@ -47,6 +47,7 @@ type PartitionOffsetStatements struct { // Prepare converts the raw SQL statements into prepared statements. // Takes a prefix to prepend to the table name used to store the partition offsets. // This allows multiple components to share the same database schema. +// nolint: safesql func (s *PartitionOffsetStatements) Prepare(db *sql.DB, prefix string) (err error) { _, err = db.Exec(strings.Replace(partitionOffsetsSchema, "${prefix}", prefix, -1)) if err != nil { diff --git a/src/github.com/matrix-org/dendrite/publicroomsapi/storage/public_rooms_table.go b/src/github.com/matrix-org/dendrite/publicroomsapi/storage/public_rooms_table.go index 5e1eb3e12..85d65c2cc 100644 --- a/src/github.com/matrix-org/dendrite/publicroomsapi/storage/public_rooms_table.go +++ b/src/github.com/matrix-org/dendrite/publicroomsapi/storage/public_rooms_table.go @@ -134,6 +134,7 @@ type publicRoomsStatements struct { updateRoomAttributeStmts map[string]*sql.Stmt } +// nolint: safesql func (s *publicRoomsStatements) prepare(db *sql.DB) (err error) { _, err = db.Exec(publicRoomsSchema) if err != nil { diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go b/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go index 0bf711323..21fe0c104 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/event_state_keys_table.go @@ -60,10 +60,6 @@ const bulkSelectEventStateKeyNIDSQL = "" + "SELECT event_state_key, event_state_key_nid FROM roomserver_event_state_keys" + " WHERE event_state_key = ANY($1)" -const selectEventStateKeySQL = "" + - "SELECT event_state_key FROM roomserver_event_state_keys" + - " WHERE event_state_key_nid = $1" - // Bulk lookup from numeric ID to string state key for that state key. // Takes an array of strings as the query parameter. const bulkSelectEventStateKeySQL = "" + @@ -73,7 +69,6 @@ const bulkSelectEventStateKeySQL = "" + type eventStateKeyStatements struct { insertEventStateKeyNIDStmt *sql.Stmt selectEventStateKeyNIDStmt *sql.Stmt - selectEventStateKeyStmt *sql.Stmt bulkSelectEventStateKeyNIDStmt *sql.Stmt bulkSelectEventStateKeyStmt *sql.Stmt } @@ -86,7 +81,6 @@ func (s *eventStateKeyStatements) prepare(db *sql.DB) (err error) { return statementList{ {&s.insertEventStateKeyNIDStmt, insertEventStateKeyNIDSQL}, {&s.selectEventStateKeyNIDStmt, selectEventStateKeyNIDSQL}, - {&s.selectEventStateKeyStmt, selectEventStateKeySQL}, {&s.bulkSelectEventStateKeyNIDStmt, bulkSelectEventStateKeyNIDSQL}, {&s.bulkSelectEventStateKeyStmt, bulkSelectEventStateKeySQL}, }.prepare(db) @@ -133,15 +127,6 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID( return result, nil } -func (s *eventStateKeyStatements) selectEventStateKey( - ctx context.Context, txn *sql.Tx, eventStateKeyNID types.EventStateKeyNID, -) (string, error) { - var eventStateKey string - stmt := common.TxStmt(txn, s.selectEventStateKeyStmt) - err := stmt.QueryRowContext(ctx, eventStateKeyNID).Scan(&eventStateKey) - return eventStateKey, err -} - func (s *eventStateKeyStatements) bulkSelectEventStateKey( ctx context.Context, eventStateKeyNIDs []types.EventStateKeyNID, ) (map[types.EventStateKeyNID]string, error) { diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/prepare.go b/src/github.com/matrix-org/dendrite/roomserver/storage/prepare.go index b19765992..61c49a3c1 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/prepare.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/prepare.go @@ -25,6 +25,7 @@ type statementList []struct { } // prepare the SQL for each statement in the list and assign the result to the prepared statement. +// nolint: safesql func (s statementList) prepare(db *sql.DB) (err error) { for _, statement := range s { if *statement.statement, err = db.Prepare(statement.sql); err != nil { From 340a84cdc01cd9c6ec1db74e5ca0f36024014593 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 14:54:17 +0100 Subject: [PATCH 5/6] Add staticcheck lint (#245) --- linter.json | 3 +-- .../matrix-org/dendrite/cmd/dendrite-room-server/main.go | 4 +++- .../dendrite/cmd/mediaapi-integration-tests/main.go | 2 +- .../dendrite/cmd/syncserver-integration-tests/testdata.go | 2 +- src/github.com/matrix-org/dendrite/common/httpapi.go | 3 ++- .../matrix-org/dendrite/mediaapi/writers/download.go | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/linter.json b/linter.json index 5fff55980..271a13ccc 100644 --- a/linter.json +++ b/linter.json @@ -17,7 +17,6 @@ "unparam", "errcheck", "vet", - "unused", - "gosimple" + "megacheck" ] } diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go index dea61f742..9da258c0e 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go @@ -80,7 +80,9 @@ func main() { aliasAPI.SetupHTTP(http.DefaultServeMux) - http.DefaultServeMux.Handle("/metrics", prometheus.Handler()) + // This is deprecated, but prometheus are still arguing on what to replace + // it with. Alternatively we could set it up manually. + http.DefaultServeMux.Handle("/metrics", prometheus.Handler()) // nolint: staticcheck, megacheck log.Info("Started room server on ", cfg.Listen.RoomServer) diff --git a/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go b/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go index c190c10bf..722cb80f3 100644 --- a/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/mediaapi-integration-tests/main.go @@ -190,7 +190,7 @@ func getMediaURI(host, endpoint, query string, components []string) string { func testUpload(host, filePath string) { fmt.Printf("==TESTING== upload %v to %v\n", filePath, host) file, err := os.Open(filePath) - defer file.Close() // nolint: errcheck + defer file.Close() // nolint: errcheck, staticcheck, megacheck if err != nil { panic(err) } diff --git a/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go b/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go index bde34ae79..4ff5d1ee4 100644 --- a/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go +++ b/src/github.com/matrix-org/dendrite/cmd/syncserver-integration-tests/testdata.go @@ -14,7 +14,7 @@ package main -// nolint: varcheck, deadcode, unused +// nolint: varcheck, deadcode, unused, megacheck const ( i0StateRoomCreate = iota i1StateAliceJoin diff --git a/src/github.com/matrix-org/dendrite/common/httpapi.go b/src/github.com/matrix-org/dendrite/common/httpapi.go index 8d93e58d1..0a1542b3e 100644 --- a/src/github.com/matrix-org/dendrite/common/httpapi.go +++ b/src/github.com/matrix-org/dendrite/common/httpapi.go @@ -52,6 +52,7 @@ func MakeFedAPI( // SetupHTTPAPI registers an HTTP API mux under /api and sets up a metrics // listener. func SetupHTTPAPI(servMux *http.ServeMux, apiMux *mux.Router) { - servMux.Handle("/metrics", prometheus.Handler()) + // This is deprecated. + servMux.Handle("/metrics", prometheus.Handler()) // nolint: megacheck, staticcheck servMux.Handle("/api/", http.StripPrefix("/api", apiMux)) } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go index c69f5ae90..901ab6d31 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -236,7 +236,7 @@ func (r *downloadRequest) respondFromLocalFile( return nil, errors.Wrap(err, "failed to get file path from metadata") } file, err := os.Open(filePath) - defer file.Close() // nolint: errcheck + defer file.Close() // nolint: errcheck, staticcheck, megacheck if err != nil { return nil, errors.Wrap(err, "failed to open file") } From 7a30f2085a89266c20fb395ab26326cf233d576a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 15:25:25 +0100 Subject: [PATCH 6/6] Add goconst linter (#246) --- linter-fast.json | 3 ++- linter.json | 3 ++- .../mediaapi/thumbnailer/thumbnailer.go | 8 +++--- .../mediaapi/thumbnailer/thumbnailer_nfnt.go | 2 +- .../dendrite/mediaapi/types/types.go | 6 +++++ .../dendrite/mediaapi/writers/download.go | 4 +-- .../dendrite/roomserver/input/membership.go | 25 ++++++++++++------- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/linter-fast.json b/linter-fast.json index fce445f20..3825fa615 100644 --- a/linter-fast.json +++ b/linter-fast.json @@ -11,6 +11,7 @@ "gas", "misspell", "errcheck", - "vet" + "vet", + "goconst" ] } diff --git a/linter.json b/linter.json index 271a13ccc..53308ba51 100644 --- a/linter.json +++ b/linter.json @@ -17,6 +17,7 @@ "unparam", "errcheck", "vet", - "megacheck" + "megacheck", + "goconst" ] } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go index 6aa76cf0f..835603732 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer.go @@ -63,22 +63,22 @@ func SelectThumbnail(desired types.ThumbnailSize, thumbnails []*types.ThumbnailM bestFit := newThumbnailFitness() for _, thumbnail := range thumbnails { - if desired.ResizeMethod == "scale" && thumbnail.ThumbnailSize.ResizeMethod != "scale" { + if desired.ResizeMethod == types.Scale && thumbnail.ThumbnailSize.ResizeMethod != types.Scale { continue } fitness := calcThumbnailFitness(thumbnail.ThumbnailSize, thumbnail.MediaMetadata, desired) - if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter { + if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == types.Crop); isBetter { bestFit = fitness chosenThumbnail = thumbnail } } for _, thumbnailSize := range thumbnailSizes { - if desired.ResizeMethod == "scale" && thumbnailSize.ResizeMethod != "scale" { + if desired.ResizeMethod == types.Scale && thumbnailSize.ResizeMethod != types.Scale { continue } fitness := calcThumbnailFitness(types.ThumbnailSize(thumbnailSize), nil, desired) - if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == "crop"); isBetter { + if isBetter := fitness.betterThan(bestFit, desired.ResizeMethod == types.Crop); isBetter { bestFit = fitness chosenThumbnailSize = (*types.ThumbnailSize)(&thumbnailSize) } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go index a55a6d2a8..caabf4207 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/thumbnailer/thumbnailer_nfnt.go @@ -149,7 +149,7 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize } start := time.Now() - width, height, err := adjustSize(dst, img, config.Width, config.Height, config.ResizeMethod == "crop", logger) + width, height, err := adjustSize(dst, img, config.Width, config.Height, config.ResizeMethod == types.Crop, logger) if err != nil { return false, err } diff --git a/src/github.com/matrix-org/dendrite/mediaapi/types/types.go b/src/github.com/matrix-org/dendrite/mediaapi/types/types.go index c7e5860de..855e8fe27 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/types/types.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/types/types.go @@ -102,3 +102,9 @@ type ActiveThumbnailGeneration struct { // The string key is a thumbnail file path PathToResult map[string]*ThumbnailGenerationResult } + +// Crop indicates we should crop the thumbnail on resize +const Crop = "crop" + +// Scale indicates we should scale the thumbnail on resize +const Scale = "scale" diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go index 901ab6d31..81907d555 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -179,9 +179,9 @@ func (r *downloadRequest) Validate() *util.JSONResponse { } // Default method to scale if not set if r.ThumbnailSize.ResizeMethod == "" { - r.ThumbnailSize.ResizeMethod = "scale" + r.ThumbnailSize.ResizeMethod = types.Scale } - if r.ThumbnailSize.ResizeMethod != "crop" && r.ThumbnailSize.ResizeMethod != "scale" { + if r.ThumbnailSize.ResizeMethod != types.Crop && r.ThumbnailSize.ResizeMethod != types.Scale { return &util.JSONResponse{ Code: 400, JSON: jsonerror.Unknown("method must be one of crop or scale"), diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/membership.go b/src/github.com/matrix-org/dendrite/roomserver/input/membership.go index f4d8e02ca..cd09001e1 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/membership.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/membership.go @@ -23,6 +23,13 @@ import ( "github.com/matrix-org/gomatrixserverlib" ) +// Membership values +// TODO: Factor these out somewhere sensible? +const join = "join" +const leave = "leave" +const invite = "invite" +const ban = "ban" + // updateMembership updates the current membership and the invites for each // user affected by a change in the current state of the room. // Returns a list of output events to write to the kafka log to inform the @@ -83,9 +90,9 @@ func updateMembership( updates []api.OutputEvent, ) ([]api.OutputEvent, error) { var err error - // Default the membership to "leave" if no event was added or removed. - old := "leave" - new := "leave" + // Default the membership to Leave if no event was added or removed. + old := leave + new := leave if remove != nil { old, err = remove.Membership() @@ -99,9 +106,9 @@ func updateMembership( return nil, err } } - if old == new && new != "join" { + if old == new && new != join { // If the membership is the same then nothing changed and we can return - // immediately, unless it's a "join" update (e.g. profile update). + // immediately, unless it's a Join update (e.g. profile update). return updates, nil } @@ -111,11 +118,11 @@ func updateMembership( } switch new { - case "invite": + case invite: return updateToInviteMembership(mu, add, updates) - case "join": + case join: return updateToJoinMembership(mu, add, updates) - case "leave", "ban": + case leave, ban: return updateToLeaveMembership(mu, add, new, updates) default: panic(fmt.Errorf( @@ -176,7 +183,7 @@ func updateToJoinMembership( for _, eventID := range retired { orie := api.OutputRetireInviteEvent{ EventID: eventID, - Membership: "join", + Membership: join, } if add != nil { orie.RetiredByEventID = add.EventID()