yvbolt/format.go

28 lines
359 B
Go
Raw Permalink Normal View History

2024-06-08 03:02:02 +00:00
package main
import (
"fmt"
"unicode/utf8"
)
func formatUtf8(in []byte) string {
if !utf8.Valid(in) {
return fmt.Sprintf("<<Invalid UTF-8 %q>>", in)
}
return string(in)
}
func formatAny(in interface{}) string {
switch in := in.(type) {
case []byte:
2024-06-08 03:02:02 +00:00
return "<<binary>>"
case string:
return in
default:
return fmt.Sprintf("%#v", in)
}
2024-06-08 03:02:02 +00:00
}