我想包装goquery.Selection以更方便地获取 HTML 和选择器字符串。
要访问 的方法goquery.Selection,我应该Get()在下面的代码中实现一些辅助方法吗?
type MySelection goquery.Selection
// Without this helper method, I should always use type conversion
// to use goquery.Selection's methods.
func (s *MySelection) Get() *goquery.Selection {
sel := s.(goquery.Selection)
return sel
}
func (s *MySelection) HTML() string {
// html, _ := s.Html() <- error
html, _ := s.Get().Html()
return html
}
func (s *MySelection) String() string {
return fmt.Sprintf("%v#%v.%v",
goquery.NodeName(s.Get()),
s.Get().AttrOr("id", "(undefined)"),
s.Get().AttrOr("class", "(undefined)"))
}
有没有更好的方法来处理这种情况?
ABOUTYOU
守着一只汪
相关分类