generateDocs produces error code markdown document for the named type.
(typeName string)
| 260 | |
| 261 | // generateDocs produces error code markdown document for the named type. |
| 262 | func (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. |
| 293 | func (g *Generator) format() []byte { |