NewGolangParser returns a new GoParser object. This object is responsible for converting Go types into the intermediate typescript AST representation. All configuration of the GoParser should be done before calling 'ToTypescript'. For usage, see 'ExampleGeneration' in convert_test.go.
()
| 52 | // 'ToTypescript'. |
| 53 | // For usage, see 'ExampleGeneration' in convert_test.go. |
| 54 | func NewGolangParser() (*GoParser, error) { |
| 55 | fileSet := token.NewFileSet() |
| 56 | config := &packages.Config{ |
| 57 | // Just accept the fact we need these flags for what we want. Feel free to add |
| 58 | // more, it'll just increase the time it takes to parse. |
| 59 | Mode: packages.NeedTypes | packages.NeedName | packages.NeedTypesInfo | |
| 60 | packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedDeps, |
| 61 | Tests: false, |
| 62 | Fset: fileSet, |
| 63 | //Dir: "/home/steven/go/src/github.com/coder/guts", |
| 64 | Context: context.Background(), |
| 65 | } |
| 66 | |
| 67 | return &GoParser{ |
| 68 | fileSet: fileSet, |
| 69 | config: config, |
| 70 | Pkgs: make(map[string]*packages.Package), |
| 71 | Reference: make(map[string]bool), |
| 72 | referencedTypes: newReferencedTypes(), |
| 73 | Prefix: make(map[string]string), |
| 74 | Skips: make(map[string]struct{}), |
| 75 | typeOverrides: map[string]TypeOverride{ |
| 76 | // Some hard coded defaults |
| 77 | "error": func() bindings.ExpressionType { |
| 78 | return ptr(bindings.KeywordString) |
| 79 | }, |
| 80 | }, |
| 81 | }, nil |
| 82 | } |
| 83 | |
| 84 | // PreserveComments will attempt to preserve any comments associated with |
| 85 | // the golang types. This feature is still a work in progress, and may not |
searching dependent graphs…