On Thu, Jun 16, 2016 at 2:11 PM, Tong Sun <suntong...@gmail.com> wrote: > How to define my own function > > > func FindUrl() { return > goquery.Find(".thing").Find(".comments.may-blank").Attr("href"); } > > so that the above code can be simplified as: > > post_url, _ := doc.FindUrl()
In your own package, you can only define new functions, not new methods. https://golang.org/ref/spec#Method_declarations says that "the receiver base type...must be declared in the same package as the method". Thus, you can write your FindUrl to be FindUrl(doc) but not doc.FindUrl() -- 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.