-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional error message to the error check
- Loading branch information
1 parent
5cbc041
commit e1ca657
Showing
3 changed files
with
20 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
package errorcheck | ||
|
||
import "log" | ||
import ( | ||
"log" | ||
) | ||
|
||
func ErrorCheck(err error) { | ||
func ErrorCheck(err error, message ...string) { | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
if len(message) != 0 { | ||
// For each message we print a new line to stderr | ||
for _, v := range message { | ||
log.Println(v) | ||
} | ||
// Then write the exit code and exits | ||
log.Fatal(err) | ||
} else { | ||
// Write the exit code and exit | ||
log.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters