Skip to content

Commit

Permalink
Fix specifying multiple domains
Browse files Browse the repository at this point in the history
This allows multiple allowed domains to be specified
  • Loading branch information
theseanything committed Oct 17, 2023
1 parent 15acc5e commit efc5d59
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Config struct {
Site string `env:"SITE"`
AllowedDomains string `env:"ALLOWED_DOMAINS"`
AllowedDomains []string `env:"ALLOWED_DOMAINS" envSeparator:","`
UserAgent string `env:"USER_AGENT" envDefault:"govukbot"`
Headers map[string]string `env:"HEADERS"`
Concurrency int `env:"CONCURRENCY" envDefault:"10"`
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func TestNewConfig(t *testing.T) {
name: "env vars",
envVars: map[string]string{
"SITE": "example.com",
"ALLOWED_DOMAINS": "example.com",
"ALLOWED_DOMAINS": "example.com,foo.bar",
"USER_AGENT": "custom-agent",
"HEADERS": "Test-Header:Test-Value",
"CONCURRENCY": "20",
"DISALLOWED_URL_RULES": "rule1,rule2",
},
expected: &Config{
Site: "example.com",
AllowedDomains: "example.com",
AllowedDomains: []string{"example.com", "foo.bar"},
UserAgent: "custom-agent",
Headers: map[string]string{
"Test-Header": "Test-Value",
Expand Down
2 changes: 1 addition & 1 deletion internal/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewCrawler(cfg *config.Config) (*Crawler, error) {
func newCollector(cfg *config.Config) (*colly.Collector, error) {
c := colly.NewCollector(
colly.UserAgent(cfg.UserAgent),
colly.AllowedDomains(cfg.AllowedDomains),
colly.AllowedDomains(cfg.AllowedDomains...),
colly.DisallowedURLFilters(cfg.DisallowedURLFilters...),
colly.Async(true),
)
Expand Down

0 comments on commit efc5d59

Please sign in to comment.