Utils methods refactored for readability
authorsrinivasreddy <thatiparthysreenivas@gmail.com>
Sat, 12 Mar 2016 19:19:53 +0000 (00:49 +0530)
committerSteve Francia <steve.francia@gmail.com>
Mon, 21 Mar 2016 23:08:49 +0000 (19:08 -0400)
utils/utils.go

index 3977a0e6228cb10b8543985aafe5c85373bed149..6f4264ccab19500fd96ed719520d34b2287feae8 100644 (file)
@@ -20,35 +20,37 @@ import (
 )
 
 func CheckErr(err error, s ...string) {
-       if err != nil {
-               if len(s) == 0 {
-                       jww.CRITICAL.Println(err)
-               } else {
-                       for _, message := range s {
-                               jww.ERROR.Println(message)
-                       }
-                       jww.ERROR.Println(err)
-               }
+       if err == nil {
+               return
+       }
+       if len(s) == 0 {
+               jww.CRITICAL.Println(err)
+               return
        }
+       for _, message := range s {
+               jww.ERROR.Println(message)
+       }
+       jww.ERROR.Println(err)
 }
 
 func StopOnErr(err error, s ...string) {
-       if err != nil {
-               if len(s) == 0 {
-                       newMessage := err.Error()
+       if err == nil {
+               return
+       }
 
-                       // Printing an empty string results in a error with
-                       // no message, no bueno.
-                       if newMessage != "" {
-                               jww.CRITICAL.Println(newMessage)
-                       }
-               } else {
-                       for _, message := range s {
-                               if message != "" {
-                                       jww.CRITICAL.Println(message)
-                               }
-                       }
+       defer os.Exit(-1)
+
+       if len(s) == 0 {
+               newMessage := err.Error()
+               // Printing an empty string results in a error with
+               // no message, no bueno.
+               if newMessage != "" {
+                       jww.CRITICAL.Println(newMessage)
+               }
+       }
+       for _, message := range s {
+               if message != "" {
+                       jww.CRITICAL.Println(message)
                }
-               os.Exit(-1)
        }
 }