MCPcopy
hub / github.com/marmotedu/iam / generateDocs

Method generateDocs

tools/codegen/codegen.go:262–290  ·  view source on GitHub ↗

generateDocs produces error code markdown document for the named type.

(typeName string)

Source from the content-addressed store, hash-verified

260
261// generateDocs produces error code markdown document for the named type.
262func (g *Generator) generateDocs(typeName string) {
263 values := make([]Value, 0, 100)
264 for _, file := range g.pkg.files {
265 // Set the state for this run of the walker.
266 file.typeName = typeName
267 file.values = nil
268 if file.file != nil {
269 ast.Inspect(file.file, file.genDecl)
270 values = append(values, file.values...)
271 }
272 }
273
274 if len(values) == 0 {
275 log.Fatalf("no values defined for type %s", typeName)
276 }
277
278 tmpl, _ := template.New("doc").Parse(errCodeDocPrefix)
279 var buf bytes.Buffer
280 _ = tmpl.Execute(&buf, "`")
281
282 // Generate code that will fail if the constants change value.
283 g.Printf(buf.String())
284 for _, v := range values {
285 code, description := v.ParseComment()
286 // g.Printf("\tregister(%s, %s, \"%s\")\n", v.originalName, code, description)
287 g.Printf("| %s | %d | %s | %s |\n", v.originalName, v.value, code, description)
288 }
289 g.Printf("\n")
290}
291
292// format returns the gofmt-ed contents of the Generator's buffer.
293func (g *Generator) format() []byte {

Callers 1

mainFunction · 0.95

Calls 5

PrintfMethod · 0.95
ParseCommentMethod · 0.80
FatalfMethod · 0.65
NewMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected