27 lines
482 B
Go
27 lines
482 B
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// typer.go
|
|
package kern
|
|
|
|
import "fmt"
|
|
|
|
type Typer interface {
|
|
TypeName() string
|
|
}
|
|
|
|
func TypeName(v any) (name string) {
|
|
if v == nil {
|
|
name = "nil"
|
|
} else if typer, ok := v.(Typer); ok {
|
|
name = typer.TypeName()
|
|
} else if _, ok := v.(int64); ok {
|
|
name = "integer"
|
|
} else if _, ok := v.(float64); ok {
|
|
name = "float"
|
|
} else {
|
|
name = fmt.Sprintf("%T", v)
|
|
}
|
|
return
|
|
}
|