Extractors refactored to support pass by value. Documentation added for request and response.

This commit is contained in:
Musab Gültekin
2019-07-04 02:13:29 +03:00
parent 71683ec6de
commit da03567fae
9 changed files with 51 additions and 28 deletions

View File

@@ -1,14 +1,22 @@
package extract
import "github.com/PuerkitoBio/goquery"
import (
"github.com/PuerkitoBio/goquery"
"strings"
)
// Text returns the combined text contents of provided selector.
type Text struct {
Name string
Selector string
Name string
Selector string
TrimSpace bool
}
// Extract returns the combined text contents of provided selector.
func (e *Text) Extract(doc *goquery.Document) (interface{}, error) {
return map[string]string{e.Name: doc.Find(e.Selector).Text()}, nil
func (e Text) Extract(sel *goquery.Selection) (interface{}, error) {
text := sel.Find(e.Selector).Text()
if e.TrimSpace {
text = strings.TrimSpace(text)
}
return map[string]string{e.Name: text}, nil
}