Add any type and output errors
This commit is contained in:
16
go-demo-4/output/errors.go
Normal file
16
go-demo-4/output/errors.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package output
|
||||
|
||||
import "github.com/fatih/color"
|
||||
|
||||
func PrintError(value any) {
|
||||
switch t := value.(type) {
|
||||
case string:
|
||||
color.Red(t)
|
||||
case int:
|
||||
color.Red("Код ошибки: %d", t)
|
||||
case error:
|
||||
color.Red(t.Error())
|
||||
default:
|
||||
color.Red("Неизвестный тип ошибки")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user