Documentation ¶
Overview ¶
Package underlying implements a converts to a type which contains only basic types.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert converts specified type to a type which contains only basic types. e.g. (MyInt is defined by "type MyInt int")
[]MyInt -> []int <-chan MyInt -> <-chan int map[MyInt]MyInt -> map[int]int
if ptrElem is true, Convert converts a pointer type to its elem type. e.g. *string -> string
Example ¶
package main import ( "fmt" "go/ast" "go/importer" "go/parser" "go/token" "go/types" "github.com/tenntenn/underlying" ) func main() { const src = `package main type MyInt int type Example struct { N MyInt S *string } func main() {}` fset := token.NewFileSet() f, err := parser.ParseFile(fset, "main.go", src, 0) if err != nil { panic(err) } info := &types.Info{ Defs: map[*ast.Ident]types.Object{}, } config := &types.Config{ Importer: importer.Default(), } pkg, err := config.Check("main", fset, []*ast.File{f}, info) if err != nil { panic(err) } typ := pkg.Scope().Lookup("Example").Type() fmt.Println(underlying.Convert(typ, true)) }
Output: struct{N int; S string}
Types ¶
type Converter ¶
type Converter struct {
PtrElem bool
}
Converter converts specified type to a type which contains only basic types.
func (*Converter) Convert ¶
Convert converts specified type to a type which contains only basic types. e.g. (MyInt is defined by "type MyInt int")
[]MyInt -> []int <-chan MyInt -> <-chan int map[MyInt]MyInt -> map[int]int
if ptrElem is true, Convert converts a pointer type to its elem type. e.g. *string -> string
Click to show internal directories.
Click to hide internal directories.