mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-13 17:33:11 +01:00
Add gosimple linter (#242)
This commit is contained in:
parent
b72142ace5
commit
cc2f755cb3
16 changed files with 28 additions and 66 deletions
|
@ -16,6 +16,7 @@
|
|||
"misspell",
|
||||
"unparam",
|
||||
"errcheck",
|
||||
"vet"
|
||||
"vet",
|
||||
"gosimple"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue