Minor simplification of internal/reader/media/media.go
- Simplify a switch-case by moving a common condition above it. - Remove a superfluous error-check: `strconv.ParseInt` returns `0` when passed an empty string.
This commit is contained in:
parent
8212f16aa2
commit
91f5522ce0
1 changed files with 10 additions and 11 deletions
|
@ -86,15 +86,17 @@ type Content struct {
|
||||||
|
|
||||||
// MimeType returns the attachment mime type.
|
// MimeType returns the attachment mime type.
|
||||||
func (mc *Content) MimeType() string {
|
func (mc *Content) MimeType() string {
|
||||||
switch {
|
if mc.Type != "" {
|
||||||
case mc.Type == "" && mc.Medium == "image":
|
|
||||||
return "image/*"
|
|
||||||
case mc.Type == "" && mc.Medium == "video":
|
|
||||||
return "video/*"
|
|
||||||
case mc.Type == "" && mc.Medium == "audio":
|
|
||||||
return "audio/*"
|
|
||||||
case mc.Type != "":
|
|
||||||
return mc.Type
|
return mc.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
switch mc.Medium {
|
||||||
|
case "image":
|
||||||
|
return "image/*"
|
||||||
|
case "video":
|
||||||
|
return "video/*"
|
||||||
|
case "audio":
|
||||||
|
return "audio/*"
|
||||||
default:
|
default:
|
||||||
return "application/octet-stream"
|
return "application/octet-stream"
|
||||||
}
|
}
|
||||||
|
@ -102,9 +104,6 @@ func (mc *Content) MimeType() string {
|
||||||
|
|
||||||
// Size returns the attachment size.
|
// Size returns the attachment size.
|
||||||
func (mc *Content) Size() int64 {
|
func (mc *Content) Size() int64 {
|
||||||
if mc.FileSize == "" {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
size, _ := strconv.ParseInt(mc.FileSize, 10, 0)
|
size, _ := strconv.ParseInt(mc.FileSize, 10, 0)
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue