mirror of https://github.com/deuill/farsight.git
Rename interface types and methods for clarity
This commit is contained in:
parent
6c76baa233
commit
0a79682ee5
|
@ -125,10 +125,10 @@ func setField(doc parser.Document, field reflect.Value) error {
|
|||
}
|
||||
case reflect.Slice:
|
||||
// Decompose document into list and prepare destination slice.
|
||||
list := doc.List()
|
||||
slice := reflect.MakeSlice(field.Type(), len(list), cap(list))
|
||||
docs := doc.Slice()
|
||||
slice := reflect.MakeSlice(field.Type(), len(docs), cap(docs))
|
||||
|
||||
for i, d := range list {
|
||||
for i, d := range docs {
|
||||
if err := setField(d, slice.Index(i)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -89,9 +89,9 @@ func (h *HTMLDocument) Filter(sel string) (parser.Document, error) {
|
|||
return sub, nil
|
||||
}
|
||||
|
||||
// List decomposes the target HTMLDocument into a slice of HTMLDocument types,
|
||||
// Slice decomposes the target HTMLDocument into a slice of HTMLDocument types,
|
||||
// each containing a single node from the parent's list of nodes.
|
||||
func (h *HTMLDocument) List() []parser.Document {
|
||||
func (h *HTMLDocument) Slice() []parser.Document {
|
||||
var docs []parser.Document
|
||||
|
||||
for _, n := range h.nodes {
|
||||
|
|
|
@ -10,13 +10,15 @@ import (
|
|||
"io"
|
||||
)
|
||||
|
||||
// Parser is an interface that wraps the Parse method.
|
||||
type Parser interface {
|
||||
Parse(io.Reader) (Document, error)
|
||||
}
|
||||
|
||||
// Document is an interface that represents a generic, introspect-able document.
|
||||
type Document interface {
|
||||
Filter(attr string) (Document, error)
|
||||
List() []Document
|
||||
Slice() []Document
|
||||
String() string
|
||||
}
|
||||
|
||||
|
|
|
@ -11,15 +11,16 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type Source interface {
|
||||
// Fetcher is an interface that wraps the Fetch method.
|
||||
type Fetcher interface {
|
||||
Fetch(src string) (io.Reader, error)
|
||||
}
|
||||
|
||||
// A map of all registered sources.
|
||||
var sources map[string]Source
|
||||
var sources map[string]Fetcher
|
||||
|
||||
// Register a source under a unique name.
|
||||
func Register(name string, rcvr Source) error {
|
||||
func Register(name string, rcvr Fetcher) error {
|
||||
if _, exists := sources[name]; exists {
|
||||
return fmt.Errorf("Source '%s' already registered, refusing to overwrite", name)
|
||||
}
|
||||
|
@ -43,5 +44,5 @@ func Fetch(src string) (io.Reader, error) {
|
|||
}
|
||||
|
||||
func init() {
|
||||
sources = make(map[string]Source)
|
||||
sources = make(map[string]Fetcher)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue