mirror of
https://github.com/rwinkhart/go-boilerplate.git
synced 2026-09-05 08:37:23 -04:00
Return errors, rather than printing them; move PrintError() to front package
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package back
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// RemoveTrailingEmptyStrings removes empty strings from the end of a slice.
|
||||
func RemoveTrailingEmptyStrings(slice []string) []string {
|
||||
for i := len(slice) - 1; i >= 0; i-- {
|
||||
@@ -14,16 +9,3 @@ func RemoveTrailingEmptyStrings(slice []string) []string {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrintError prints an error message in the standard libmutton format and exits with the specified exit code.
|
||||
// Requires: message (the error message to print),
|
||||
// exitCode (the exit code to use),
|
||||
// forceHardExit (if true, exit immediately; if false, allow soft exit for interactive clients).
|
||||
func PrintError(message string, exitCode int, forceHardExit bool) {
|
||||
fmt.Println(AnsiError + message + AnsiReset)
|
||||
if forceHardExit {
|
||||
os.Exit(exitCode)
|
||||
} else {
|
||||
Exit(exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user