Replaced error if/else checks with switch/case, to keep things consistent

This commit is contained in:
Seednode 2022-11-10 00:29:06 -06:00
parent 283b4fccec
commit 4b596743f7
2 changed files with 10 additions and 7 deletions

View File

@ -112,17 +112,19 @@ func humanReadableSize(bytes int) string {
func getImageDimensions(path string) (*Dimensions, error) {
file, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) {
switch {
case errors.Is(err, os.ErrNotExist):
return &Dimensions{}, nil
} else if err != nil {
case err != nil:
return &Dimensions{}, err
}
defer file.Close()
myImage, _, err := image.DecodeConfig(file)
if errors.Is(err, image.ErrFormat) {
switch {
case errors.Is(err, image.ErrFormat):
return &Dimensions{Width: 0, Height: 0}, nil
} else if err != nil {
case err != nil:
return &Dimensions{}, err
}
@ -357,9 +359,10 @@ func pathIsValid(filePath string, paths []string) bool {
func isImage(path string) (bool, error) {
file, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) {
switch {
case errors.Is(err, os.ErrNotExist):
return false, nil
} else if err != nil {
case err != nil:
return false, err
}
defer file.Close()

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)
var Version = "0.25.0"
var Version = "0.25.1"
func init() {
rootCmd.AddCommand(versionCmd)