-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
51 lines (44 loc) · 1.54 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package seltabl
import (
"reflect"
)
var (
// cSels is a list of supported control selectors
cSels = []string{ctlInnerTextSelector, ctlAttrSelector}
)
const (
// selectorDataTag is the tag used to mark a data cell.
selectorDataTag = "dSel"
// selectorHeaderTag is the tag used to mark a header selector.
selectorHeaderTag = "hSel"
// selectorTag is the tag used to mark a selector.
selectorQueryTag = "qSel"
// selectorControlTag is the tag used to signify selecting aspects of a cell
selectorControlTag = "ctl"
// cSelInnerTextSelector is the selector used to extract text from a cell.
ctlInnerTextSelector = "text"
// cSelAttrSelector is the selector used to extract attributes from a cell.
ctlAttrSelector = "query"
)
// SelectorConfig is a struct for configuring a selector
type SelectorConfig struct {
DataSelector string // selector for the data cell
HeadSelector string // selector for the header cell
QuerySelector string // selector for the data cell
ControlTag string // tag used to signify selecting aspects of a cell
}
// NewSelectorConfig parses a struct tag and returns a SelectorConfig
func NewSelectorConfig(tag reflect.StructTag) *SelectorConfig {
cfg := &SelectorConfig{
HeadSelector: tag.Get(selectorHeaderTag),
DataSelector: tag.Get(selectorDataTag),
QuerySelector: tag.Get(selectorQueryTag),
ControlTag: tag.Get(selectorControlTag),
}
if cfg.QuerySelector == "" || cfg.DataSelector == ctlAttrSelector {
cfg.QuerySelector, cfg.ControlTag =
ctlInnerTextSelector,
ctlInnerTextSelector
}
return cfg
}