unhtml
unhtml copied to clipboard
converter inheritance of parent struct funcs
Hey! :)
Is there any way to inherit parent node/struct funcs?
For example, a situation that can be expressed with such code.
type ParentNode struct {
ListOfSomething []struct{
Data string `html:"div > span" converter:"Trim"`
} `html:".awesome-div"`
}
func (ParrentNode) Trim(data string) (string, error) {
. . .
}
When trying to use Trim
from ParentNode
for Data
I get the error "converter not exist: Trim". And the only way that I found is to take out the structures, and attach to them their personal convertors.
type ParentNode struct {
ListOfSomething []Something `html:".awesome-div"`
}
type Something struct {
Data string `html:"div > span" converter:"Trim"`
}
func (Something) Trim(data string) (string, error) {
. . .
}
This isn't a big problem for small structs. But with a deep nesting this will become a big problem with a bloating and duplicated amount of code.
PS: Thank you so much for the work and time that you spent on creating this package. I don’t understand why such a convenient tool has such little fame.
Thx for your advice.
I think inheriting methods is unnecessary. On the one hand, using underlying types straightly may be unreadable for me. On the other hand, a converter may should be normal function instead of method.
Do you think using normal functions is a better choise?