36 lines
496 B
Go
36 lines
496 B
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// formatter.go
|
|
package expr
|
|
|
|
import "fmt"
|
|
|
|
type FmtOpt uint16
|
|
|
|
const (
|
|
TTY FmtOpt = 1 << iota
|
|
MultiLine
|
|
Base2
|
|
Base8
|
|
Base10
|
|
Base16
|
|
)
|
|
|
|
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
|
|
}
|