MCPcopy Index your code
hub / github.com/coder/guts / main

Function main

example/simple/main.go:23–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21}
22
23func 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}

Callers

nothing calls this directly

Calls 10

NewGolangParserFunction · 0.92
StandardMappingsFunction · 0.92
IncludeGenerateMethod · 0.80
IncludeCustomMethod · 0.80
ExcludeCustomMethod · 0.80
PreserveCommentsMethod · 0.80
ToTypescriptMethod · 0.80
ApplyMutationsMethod · 0.80
SerializeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…