On Thursday, June 16, 2016 at 12:11:54 AM UTC-4, Tong Sun wrote: > > Let me explain with an example, > > For goquery, most functions are of type "func (s *Selection) Xxx(selector > string) *Selection". > For e.g., "Find" is: > > func (s *Selection > <https://godoc.org/github.com/PuerkitoBio/goquery#Selection>) Find(selector > string <https://godoc.org/builtin#string>) *Selection > <https://godoc.org/github.com/PuerkitoBio/goquery#Selection> > > > > What's the simplest way for me to define my own function of such type, > which can be used as a replacement for them. > > E.g., for a code like, > > post_url, _ := doc.Find(".thing").Find(".comments.may-blank").Attr("href") > > > > 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*() > > > ? Or, is it possible to define FindUrlN() as > "goquery.Find(".thing").Find(".comments.may-blank")", so that I can do this: > > post_url, _ := doc.FindUrlN().Attr("href") > > ? Thanks > > > PS, If you need some code to be based on, I've prepare it here -- https://github.com/suntong/kuaizh/blob/master/crawler/reddit.go
PPS, Does it make any difference for other's packages or my own package? I mean, if I create my own module, and import that module in another program, is there any advantages I can take, to extend the functionality of my own module from my other program, since I can control both? Thanks -- 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.