diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-09 16:38:28 +0300 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-27 11:36:53 +0300 |
commit | 39b7e2c35b2f609623ae483ee3f607b3da42808e (patch) | |
tree | 1dfd076dff5dad0a86064edb36eb9097ccde2815 /internal/redirects/redirects.go | |
parent | 31b7783c26879de6f170e40777c799dfd797213b (diff) |
Apply review suggestions
Diffstat (limited to 'internal/redirects/redirects.go')
-rw-r--r-- | internal/redirects/redirects.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/internal/redirects/redirects.go b/internal/redirects/redirects.go index 3c214073..04815404 100644 --- a/internal/redirects/redirects.go +++ b/internal/redirects/redirects.go @@ -26,8 +26,7 @@ const ( ) var ( - // hack, todo: properly pass config context to internals - cfg, _ = config.LoadConfig() + cfg = config.Redirects{} // ErrNoRedirect is the error thrown when a no redirect rule matches while trying to Rewrite URL. // This means that no redirect applies to the URL and you can fallback to serving actual content instead. ErrNoRedirect = errors.New("no redirect found") @@ -44,10 +43,14 @@ var ( errNoParams = errors.New("params not supported") errUnsupportedStatus = errors.New("status not supported") errNoForce = errors.New("force! not supported") - errTooManyPathSegments = fmt.Errorf("url path cannot contain more than %d forward slashes", cfg.Redirects.MaxConfigSize) + errTooManyPathSegments = fmt.Errorf("url path cannot contain more than %d forward slashes", cfg.MaxConfigSize) regexpPlaceholder = regexp.MustCompile(`(?i)/:[a-z]+`) ) +func SetConfig(redirectsConfig config.Redirects) { + cfg = redirectsConfig +} + type Redirects struct { rules []netlifyRedirects.Rule error error @@ -63,13 +66,13 @@ func (r *Redirects) Status() string { messages = append(messages, fmt.Sprintf("%d rules", len(r.rules))) for i, rule := range r.rules { - if i >= cfg.Redirects.MaxConfigSize { + if i >= cfg.MaxConfigSize { messages = append([]string{ fmt.Sprintf( "The _redirects file contains (%d) rules, more than the maximum of %d rules. Only the first %d rules will be processed.", len(r.rules), - cfg.Redirects.MaxRuleCount, - cfg.Redirects.MaxRuleCount, + cfg.MaxRuleCount, + cfg.MaxRuleCount, )}, messages..., ) @@ -120,7 +123,7 @@ func ParseRedirects(ctx context.Context, root vfs.Root) *Redirects { return &Redirects{error: errNeedRegularFile} } - if int(fi.Size()) > cfg.Redirects.MaxConfigSize { + if int(fi.Size()) > cfg.MaxConfigSize { return &Redirects{error: errFileTooLarge} } |