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) { func getImageDimensions(path string) (*Dimensions, error) {
file, err := os.Open(path) file, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) { switch {
case errors.Is(err, os.ErrNotExist):
return &Dimensions{}, nil return &Dimensions{}, nil
} else if err != nil { case err != nil:
return &Dimensions{}, err return &Dimensions{}, err
} }
defer file.Close() defer file.Close()
myImage, _, err := image.DecodeConfig(file) 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 return &Dimensions{Width: 0, Height: 0}, nil
} else if err != nil { case err != nil:
return &Dimensions{}, err return &Dimensions{}, err
} }
@ -357,9 +359,10 @@ func pathIsValid(filePath string, paths []string) bool {
func isImage(path string) (bool, error) { func isImage(path string) (bool, error) {
file, err := os.Open(path) file, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) { switch {
case errors.Is(err, os.ErrNotExist):
return false, nil return false, nil
} else if err != nil { case err != nil:
return false, err return false, err
} }
defer file.Close() defer file.Close()

View File

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