mirror of
https://github.com/rwinkhart/go-boilerplate.git
synced 2026-09-03 15:47:24 -04:00
Return errors, rather than printing them; move PrintError() to front package
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package front
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
)
|
||||
|
||||
// PrintError prints an error message in the MUTN 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(back.AnsiError + message + back.AnsiReset)
|
||||
if forceHardExit {
|
||||
os.Exit(exitCode)
|
||||
} else {
|
||||
back.Exit(exitCode)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user