Standard library / go/doc
go/doc.Package.Filter()
Removes documentation entries whose names fail the filter; it does not rewrite source code. Expected stdout: '1 0\n'.
Formal Syntax & Structure
go syntaxgo
func (p *Package) Filter(f Filter)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| f | Filter | Input to the operation as described above. |
Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/doc" "go/parser" "go/token")
func check(e error) { if e != nil { panic(e) }}func packageDoc(mode doc.Mode) *doc.Package { fs := token.NewFileSet() f, e := parser.ParseFile(fs, "demo.go", `// Package demo documents values.package demo// Answer is a number.const Answer=42// hidden is private.var hidden=1// Item describes a value.type Item struct{}// Work performs work.func Work(){}// BUG(user): fix example.`, parser.ParseComments) check(e) p, e := doc.NewFromFiles(fs, []*ast.File{f}, "example.invalid/demo", mode) check(e) return p}
func main() { p := packageDoc(0) p.Filter(func(s string) bool { return s == "Answer" }) fmt.Println(len(p.Consts), len(p.Funcs))}