Add goconst linter (#246)
parent
340a84cdc0
commit
7a30f2085a
|
@ -11,6 +11,7 @@
|
||||||
"gas",
|
"gas",
|
||||||
"misspell",
|
"misspell",
|
||||||
"errcheck",
|
"errcheck",
|
||||||
"vet"
|
"vet",
|
||||||
|
"goconst"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"unparam",
|
"unparam",
|
||||||
"errcheck",
|
"errcheck",
|
||||||
"vet",
|
"vet",
|
||||||
"megacheck"
|
"megacheck",
|
||||||
|
"goconst"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,22 +63,22 @@ func SelectThumbnail(desired types.ThumbnailSize, thumbnails []*types.ThumbnailM
|
||||||
bestFit := newThumbnailFitness()
|
bestFit := newThumbnailFitness()
|
||||||
|
|
||||||
for _, thumbnail := range thumbnails {
|
for _, thumbnail := range thumbnails {
|
||||||
if desired.ResizeMethod == "scale" && thumbnail.ThumbnailSize.ResizeMethod != "scale" {
|
if desired.ResizeMethod == types.Scale && thumbnail.ThumbnailSize.ResizeMethod != types.Scale {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fitness := calcThumbnailFitness(thumbnail.ThumbnailSize, thumbnail.MediaMetadata, desired)
|
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
|
bestFit = fitness
|
||||||
chosenThumbnail = thumbnail
|
chosenThumbnail = thumbnail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, thumbnailSize := range thumbnailSizes {
|
for _, thumbnailSize := range thumbnailSizes {
|
||||||
if desired.ResizeMethod == "scale" && thumbnailSize.ResizeMethod != "scale" {
|
if desired.ResizeMethod == types.Scale && thumbnailSize.ResizeMethod != types.Scale {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fitness := calcThumbnailFitness(types.ThumbnailSize(thumbnailSize), nil, desired)
|
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
|
bestFit = fitness
|
||||||
chosenThumbnailSize = (*types.ThumbnailSize)(&thumbnailSize)
|
chosenThumbnailSize = (*types.ThumbnailSize)(&thumbnailSize)
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ func createThumbnail(src types.Path, img image.Image, config types.ThumbnailSize
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,3 +102,9 @@ type ActiveThumbnailGeneration struct {
|
||||||
// The string key is a thumbnail file path
|
// The string key is a thumbnail file path
|
||||||
PathToResult map[string]*ThumbnailGenerationResult
|
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"
|
||||||
|
|
|
@ -179,9 +179,9 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
|
||||||
}
|
}
|
||||||
// Default method to scale if not set
|
// Default method to scale if not set
|
||||||
if r.ThumbnailSize.ResizeMethod == "" {
|
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{
|
return &util.JSONResponse{
|
||||||
Code: 400,
|
Code: 400,
|
||||||
JSON: jsonerror.Unknown("method must be one of crop or scale"),
|
JSON: jsonerror.Unknown("method must be one of crop or scale"),
|
||||||
|
|
|
@ -23,6 +23,13 @@ import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"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
|
// updateMembership updates the current membership and the invites for each
|
||||||
// user affected by a change in the current state of the room.
|
// 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
|
// Returns a list of output events to write to the kafka log to inform the
|
||||||
|
@ -83,9 +90,9 @@ func updateMembership(
|
||||||
updates []api.OutputEvent,
|
updates []api.OutputEvent,
|
||||||
) ([]api.OutputEvent, error) {
|
) ([]api.OutputEvent, error) {
|
||||||
var err error
|
var err error
|
||||||
// Default the membership to "leave" if no event was added or removed.
|
// Default the membership to Leave if no event was added or removed.
|
||||||
old := "leave"
|
old := leave
|
||||||
new := "leave"
|
new := leave
|
||||||
|
|
||||||
if remove != nil {
|
if remove != nil {
|
||||||
old, err = remove.Membership()
|
old, err = remove.Membership()
|
||||||
|
@ -99,9 +106,9 @@ func updateMembership(
|
||||||
return nil, err
|
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
|
// 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
|
return updates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +118,11 @@ func updateMembership(
|
||||||
}
|
}
|
||||||
|
|
||||||
switch new {
|
switch new {
|
||||||
case "invite":
|
case invite:
|
||||||
return updateToInviteMembership(mu, add, updates)
|
return updateToInviteMembership(mu, add, updates)
|
||||||
case "join":
|
case join:
|
||||||
return updateToJoinMembership(mu, add, updates)
|
return updateToJoinMembership(mu, add, updates)
|
||||||
case "leave", "ban":
|
case leave, ban:
|
||||||
return updateToLeaveMembership(mu, add, new, updates)
|
return updateToLeaveMembership(mu, add, new, updates)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf(
|
panic(fmt.Errorf(
|
||||||
|
@ -176,7 +183,7 @@ func updateToJoinMembership(
|
||||||
for _, eventID := range retired {
|
for _, eventID := range retired {
|
||||||
orie := api.OutputRetireInviteEvent{
|
orie := api.OutputRetireInviteEvent{
|
||||||
EventID: eventID,
|
EventID: eventID,
|
||||||
Membership: "join",
|
Membership: join,
|
||||||
}
|
}
|
||||||
if add != nil {
|
if add != nil {
|
||||||
orie.RetiredByEventID = add.EventID()
|
orie.RetiredByEventID = add.EventID()
|
||||||
|
|
Loading…
Reference in New Issue