New interface to Typer: the function TypeName() returns a more readable type name
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user