()
| 21 | } |
| 22 | |
| 23 | func main() { |
| 24 | golang, _ := guts.NewGolangParser() |
| 25 | // Generate the typescript types for this package |
| 26 | _ = golang.IncludeGenerate("github.com/coder/guts/example/simple") |
| 27 | // Map time.Time to string |
| 28 | _ = golang.IncludeCustom(map[string]string{ |
| 29 | "time.Time": "string", |
| 30 | }) |
| 31 | // Common standard mappings exist as an easy starting place. |
| 32 | golang.IncludeCustomDeclaration(config.StandardMappings()) |
| 33 | |
| 34 | // Exclude SecondaryType from output |
| 35 | _ = golang.ExcludeCustom("github.com/coder/guts/example/simple.SecondaryType") |
| 36 | |
| 37 | // Optionally bring over the golang comments to the typescript output |
| 38 | golang.PreserveComments() |
| 39 | |
| 40 | // Convert the golang types to typescript AST |
| 41 | ts, _ := golang.ToTypescript() |
| 42 | |
| 43 | // ApplyMutations allows adding in generation opinions to the typescript output. |
| 44 | // The basic generator has no opinions, so mutations are required to make the output |
| 45 | // more usable and idiomatic. |
| 46 | ts.ApplyMutations( |
| 47 | // Export all top level types |
| 48 | config.ExportTypes, |
| 49 | // Readonly changes all fields and types to being immutable. |
| 50 | // Useful if the types are only used for api responses, which should |
| 51 | // not be modified. |
| 52 | //config.ReadOnly, |
| 53 | ) |
| 54 | |
| 55 | // to see the AST tree |
| 56 | //ts.ForEach(func(key string, node bindings.Node) { |
| 57 | // walk.Walk(walk.PrintingVisitor(0), node.Node) |
| 58 | //}) |
| 59 | |
| 60 | output, _ := ts.Serialize() |
| 61 | fmt.Println(output) |
| 62 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…