A slightly different problem, but you might be interested in this code that I use to find the doc comment for a method that's been discovered through go/types:
https://play.golang.org/p/POH1FwOCsZ On 27 September 2016 at 01:46, Dan Kortschak <dan.kortsc...@adelaide.edu.au> wrote: > Is there a nicer way to do this than what I have here? > > func MethodDocComments(path string) (map[string]string, error) { > fset := token.NewFileSet() > pkgs, err := parser.ParseDir(fset, path, nil, parser.ParseComments) > if err != nil { > return nil, err > } > > docs := make(map[string]string) > for _, p := range pkgs { > for _, t := range doc.New(p, path, > doc.AllDecls|doc.AllMethods).Types { > for _, f := range t.Methods { > d := fmt.Sprint("// ", strings.Replace(f.Doc, > "\n", "\n// ", -1)) > docs[f.Name] = strings.TrimSuffix(d, "// ") > } > } > } > return docs, nil > } > > Ideally, I'd like to just crib the comments directly from the source, > but I don't see an easy way to do that via the AST, but the string > munging above just feels wrong. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.