github.com/podhmo/reflect-shape@v0.4.3/api.go (about) 1 package reflectshape 2 3 import ( 4 "go/token" 5 6 "github.com/podhmo/reflect-shape/metadata" 7 ) 8 9 type Config struct { 10 SkipComments bool // if true, skip extracting argNames and comments 11 FillArgNames bool // func(context.Context, int) -> func(ctx context.Context, arg0 int) 12 FillReturnNames bool // func() (int, error) -> func() (ret0, err) 13 IncludeGoTestFiles bool 14 15 DocTruncationSize int 16 17 Fset *token.FileSet 18 extractor *Extractor 19 lookup *metadata.Lookup 20 } 21 22 var ( 23 DocTruncationSize = 10 24 ) 25 26 func (c *Config) Extract(ob interface{}) *Shape { 27 if c.DocTruncationSize == 0 { 28 c.DocTruncationSize = DocTruncationSize 29 } 30 31 if c.lookup == nil && !c.SkipComments { 32 if c.Fset == nil { 33 c.Fset = token.NewFileSet() 34 } 35 c.lookup = metadata.NewLookup(c.Fset) 36 c.lookup.IncludeGoTestFiles = c.IncludeGoTestFiles 37 c.lookup.IncludeUnexported = true 38 } 39 if c.extractor == nil { 40 c.extractor = &Extractor{ 41 Config: c, 42 Lookup: c.lookup, 43 seen: map[ID]*Shape{}, 44 packages: map[string]*Package{}, 45 } 46 } 47 return c.extractor.Extract(ob) 48 } 49 50 func (c *Config) Visited() map[ID]*Shape { 51 return c.extractor.Visited() 52 }