Configure headless browser address
Add `browser_address` configuration setting to define where is the headless browser instead of relying on the default value. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
6f002f007d
commit
45025def65
5 changed files with 11 additions and 9 deletions
|
@ -75,6 +75,7 @@ Options:
|
|||
* `hashtags`: list of key/value used to append hashtags to each tweet. Key is the pattern to match in the product name, value is the string to append to the tweet. For example, `{"twitter": {"hashtags": [{"rtx 3090": "#nvidia #rtx3090"}]}}` will detect `rtx 3090` to append `#nvidia #rtx3090` at the end of the tweet.
|
||||
* `include_regex` (optional): include products with a name matching this regexp
|
||||
* `exclude_regex` (optional): exclude products with a name matching this regexp
|
||||
* `browser_address` (optional): set headless browser address (ex: `http://127.0.0.1:9222`)
|
||||
|
||||
## How to contribute
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import (
|
|||
|
||||
// Config to store JSON configuration
|
||||
type Config struct {
|
||||
TwitterConfig `json:"twitter"`
|
||||
URLs []string `json:"urls"`
|
||||
IncludeRegex string `json:"include_regex"`
|
||||
ExcludeRegex string `json:"exclude_regex"`
|
||||
TwitterConfig `json:"twitter"`
|
||||
URLs []string `json:"urls"`
|
||||
IncludeRegex string `json:"include_regex"`
|
||||
ExcludeRegex string `json:"exclude_regex"`
|
||||
BrowserAddress string `json:"browser_address"`
|
||||
}
|
||||
|
||||
// TwitterConfig to store Twitter API secrets
|
||||
|
|
2
main.go
2
main.go
|
@ -100,7 +100,7 @@ func main() {
|
|||
}
|
||||
|
||||
// create parser
|
||||
parser, err := NewParser(config.IncludeRegex, config.ExcludeRegex)
|
||||
parser, err := NewParser(config.BrowserAddress, config.IncludeRegex, config.ExcludeRegex)
|
||||
if err != nil {
|
||||
log.Fatalf("could not create parser: %s", err)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type Parser struct {
|
|||
}
|
||||
|
||||
// NewParser to create a new Parser instance
|
||||
func NewParser(includeRegex string, excludeRegex string) (*Parser, error) {
|
||||
func NewParser(browserAddress string, includeRegex string, excludeRegex string) (*Parser, error) {
|
||||
var err error
|
||||
var includeRegexCompiled, excludeRegexCompiled *regexp.Regexp
|
||||
|
||||
|
@ -44,7 +44,7 @@ func NewParser(includeRegex string, excludeRegex string) (*Parser, error) {
|
|||
|
||||
log.Debugf("creating context with headless browser drivers")
|
||||
ctx := context.Background()
|
||||
ctx = drivers.WithContext(ctx, cdp.NewDriver())
|
||||
ctx = drivers.WithContext(ctx, cdp.NewDriver(cdp.WithAddress(browserAddress)))
|
||||
ctx = drivers.WithContext(ctx, http.NewDriver(), drivers.AsDefault())
|
||||
|
||||
return &Parser{
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestFilterInclusive(t *testing.T) {
|
|||
|
||||
for i, tc := range tests {
|
||||
t.Run(fmt.Sprintf("TestFilterInclusive#%d", i), func(t *testing.T) {
|
||||
p, err := NewParser(tc.regex, "")
|
||||
p, err := NewParser("", tc.regex, "")
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize parser: %s", err)
|
||||
} else {
|
||||
|
@ -58,7 +58,7 @@ func TestFilterExclusive(t *testing.T) {
|
|||
|
||||
for i, tc := range tests {
|
||||
t.Run(fmt.Sprintf("TestFilterExclusive#%d", i), func(t *testing.T) {
|
||||
p, err := NewParser("", tc.regex)
|
||||
p, err := NewParser("", "", tc.regex)
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize parser: %s", err)
|
||||
} else {
|
||||
|
|
Reference in a new issue