factor out logging

This commit is contained in:
2025-12-14 10:19:25 -05:00
parent 422db7490a
commit f0e1f52ae2
3 changed files with 84 additions and 23 deletions

55
src/ui/ui.go Normal file
View File

@@ -0,0 +1,55 @@
package ui
import (
"errors"
"fes/src/config"
"fmt"
"strings"
"github.com/fatih/color"
)
func Path(path string, err error) {
path = strings.TrimPrefix(path, "/")
if path == "" {
path = "/"
}
fmt.Printf("> %s ", path)
if err == nil {
OK("ok")
return
} else if errors.Is(err, config.ErrRouteMiss) {
WARN(config.ErrRouteMiss.Error())
} else {
ERROR("bad")
}
}
func Warning(msg string, err error) error {
fmt.Printf("fes: %s: %v\n", color.MagentaString("warning"), err)
return err
}
func Error(msg string, err error) error {
fmt.Printf("fes: %s: %v\n", color.RedString("error"), err)
return err
}
func Fatal(msg string, err error) error {
fmt.Printf("fes: %s: %v\n", color.RedString("fatal"), err)
panic(err)
}
func OK(msg string) {
color.Green(msg)
}
func WARN(msg string) {
color.Magenta(msg)
}
func ERROR(msg string) {
color.Red(msg)
}