feat: SlickVPN Support (#961)

- `internal/updater/html` package
- Add unit tests for slickvpn updating code
- Change shared html package to be more share-able
- Split html utilities in multiple files
- Fix processing .ovpn files with prefix space

Authored by @Rohaq 
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
This commit is contained in:
Richard Hodgson
2022-08-15 16:25:06 +01:00
committed by GitHub
parent 617bd0c600
commit d0dfc21e2b
27 changed files with 2582 additions and 16 deletions

View File

@@ -0,0 +1,43 @@
package html
import (
"golang.org/x/net/html"
)
type MatchFunc func(node *html.Node) (match bool)
func MatchID(id string) MatchFunc {
return func(node *html.Node) (match bool) {
if node == nil {
return false
}
return Attribute(node, "id") == id
}
}
func MatchData(data string) MatchFunc {
return func(node *html.Node) (match bool) {
return node != nil && node.Type == html.ElementNode && node.Data == data
}
}
func DirectChild(parent *html.Node,
matchFunc MatchFunc) (child *html.Node) {
for child := parent.FirstChild; child != nil; child = child.NextSibling {
if matchFunc(child) {
return child
}
}
return nil
}
func DirectChildren(parent *html.Node,
matchFunc MatchFunc) (children []*html.Node) {
for child := parent.FirstChild; child != nil; child = child.NextSibling {
if matchFunc(child) {
children = append(children, child)
}
}
return children
}