-
Notifications
You must be signed in to change notification settings - Fork 31
Description
In the sibling xmlquery package, the Node struct has public methods;
SelectElement(name string) *Node and
SelectElements(name string []*Node
jsonquery by comparison only has SelectElement.
Given both packages export the global function Find and FindOne both can obviously be implemented for JSON, as they already are.
I propose a change where jsonquery's SelectElement implementation mimics xmlquery's and internally calls FindOne, and similarly add SelectElements that internally calls Find.
To this end, both node types can be identified and used with an interface of
type Selector interface {
InnerText() string
SelectElement(name string) Selector
SelectElements(name string) []Selector
}
Allowing basic manipulation of both file types to only differ during load.
The alternative to this being using Query and QueryAll to allow errors to be returned, instead of simply returning a nil result/panicking, or implementing both sets as methods in each package and allowing users to make the selection.
Is this proposal sound and within the intended scope of this project?
If so I will make the changes and a pull request.