From 6a2cc5b1571388e340d17bb8bbb1182bf4980a3b Mon Sep 17 00:00:00 2001 From: Catherine Date: Mon, 22 Sep 2025 19:13:14 +0000 Subject: [PATCH] Minor refactor. NFC --- src/wildcard.go | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/wildcard.go b/src/wildcard.go index 19a85b0..b792dea 100644 --- a/src/wildcard.go +++ b/src/wildcard.go @@ -70,36 +70,33 @@ func HandleWildcardFallback(w http.ResponseWriter, r *http.Request) (bool, error return false, nil } -func ConfigureWildcards(config []WildcardConfig) error { - for _, wildcardConfig := range config { - wildcardPattern := WildcardPattern{ - Domain: strings.Split(wildcardConfig.Domain, "."), - } - - template, err := fasttemplate.NewTemplate(wildcardConfig.CloneURL, "<", ">") +func ConfigureWildcards(configs []WildcardConfig) error { + for _, config := range configs { + cloneURLTemplate, err := fasttemplate.NewTemplate(config.CloneURL, "<", ">") if err != nil { return fmt.Errorf("wildcard pattern: clone URL: %w", err) - } else { - wildcardPattern.CloneURL = template } - for _, indexRepo := range wildcardConfig.IndexRepos { - template, err := fasttemplate.NewTemplate(indexRepo, "<", ">") + var indexRepoTemplates []*fasttemplate.Template + for _, indexRepo := range config.IndexRepos { + indexRepoTemplate, err := fasttemplate.NewTemplate(indexRepo, "<", ">") if err != nil { - return fmt.Errorf("wildcard pattern: clone URL: %w", err) - } else { - wildcardPattern.IndexRepos = append(wildcardPattern.IndexRepos, template) + return fmt.Errorf("wildcard pattern: index repo: %w", err) } + indexRepoTemplates = append(indexRepoTemplates, indexRepoTemplate) } - if wildcardConfig.FallbackProxyTo != "" { - wildcardPattern.FallbackURL, err = url.Parse(wildcardConfig.FallbackProxyTo) - if err != nil { - return fmt.Errorf("wildcard pattern: fallback URL: %w", err) - } + fallbackURL, err := url.Parse(config.FallbackProxyTo) + if err != nil { + return fmt.Errorf("wildcard pattern: fallback URL: %w", err) } - wildcardPatterns = append(wildcardPatterns, &wildcardPattern) + wildcardPatterns = append(wildcardPatterns, &WildcardPattern{ + Domain: strings.Split(config.Domain, "."), + CloneURL: cloneURLTemplate, + IndexRepos: indexRepoTemplates, + FallbackURL: fallbackURL, + }) } return nil }