New interface to Typer: the function TypeName() returns a more readable type name

This commit is contained in:
2024-05-19 02:23:28 +02:00
parent 9967918418
commit b92b19e1dd
4 changed files with 37 additions and 3 deletions
+15
View File
@@ -4,6 +4,8 @@
// formatter.go
package expr
import "fmt"
type FmtOpt uint16
const (
@@ -18,3 +20,16 @@ const (
type Formatter interface {
ToString(options FmtOpt) string
}
type Typer interface {
TypeName() string
}
func getTypeName(v any) (name string) {
if typer, ok := v.(Typer); ok {
name = typer.TypeName()
} else {
name = fmt.Sprintf("%T", v)
}
return
}