Skip to content

Commit 93e4e02

Browse files
authored
Merge pull request #866 from tieubaovi0217/tieubaovi0217/simple-refactor
Refactor parseSettingsFromEnv to avoid magic numbers
2 parents 157009d + 924a0de commit 93e4e02

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

colly.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ const (
214214
CheckRevisitKey
215215
)
216216

217+
// The prefix for environment variables of Colly settings
218+
const envVariablePrefix = "COLLY_"
219+
217220
var (
218221
// ErrForbiddenDomain is the error thrown if visiting
219222
// a domain which is not allowed in AllowedDomains
@@ -1507,10 +1510,10 @@ func (c *Collector) checkRedirectFunc() func(req *http.Request, via []*http.Requ
15071510

15081511
func (c *Collector) parseSettingsFromEnv() {
15091512
for _, e := range os.Environ() {
1510-
if !strings.HasPrefix(e, "COLLY_") {
1513+
if !strings.HasPrefix(e, envVariablePrefix) {
15111514
continue
15121515
}
1513-
pair := strings.SplitN(e[6:], "=", 2)
1516+
pair := strings.SplitN(e[len(envVariablePrefix):], "=", 2)
15141517
if f, ok := envMap[pair[0]]; ok {
15151518
f(c, pair[1])
15161519
} else {

0 commit comments

Comments
 (0)