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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to