我想用我自己的方法扩展现有的goquery.Selection类型,并能够从包的选择器中使用它。我知道我无法“修补”现有方法——我需要创建一个新方法。但是如何强制现有的包函数使用我的新类型?我通常缺少什么,或者没有“好的”方法可以做到这一点,最好使用函数?


package main


import (

    "fmt"

    "github.com/PuerkitoBio/goquery"

)


type customSelection goquery.Selection


func (s *customSelection) CustomMethod() int {

    return 1

}


doc.Find("*").Each(func(i int, s *goquery.Selection) {

  fmt.Println(s.CustomMethod())  // does not works since its still "goquery.Selection"

  // how do I can get a result with customSelection type here? 

})