From dc8cea6d575ff3510d7ed293207390f06700dfba Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Wed, 4 May 2022 13:47:08 +0200 Subject: [PATCH] PR comments config --- setup/config/config_global.go | 58 ++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 10f277969..25ea91d43 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -288,37 +288,39 @@ func (c *UserConsentOptions) Defaults() { } func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool) { - if c.Enabled { - checkNotEmpty(configErrors, "template_dir", c.TemplateDir) - checkNotEmpty(configErrors, "version", c.Version) - checkNotEmpty(configErrors, "policy_name", c.PolicyName) - checkNotEmpty(configErrors, "form_secret", c.FormSecret) - checkNotEmpty(configErrors, "base_url", c.BaseURL) - if len(*configErrors) > 0 { - return - } + if !c.Enabled { + return + } - p, err := filepath.Abs(c.TemplateDir) - if err != nil { - configErrors.Add("unable to get template directory") - return - } + checkNotEmpty(configErrors, "template_dir", c.TemplateDir) + checkNotEmpty(configErrors, "version", c.Version) + checkNotEmpty(configErrors, "policy_name", c.PolicyName) + checkNotEmpty(configErrors, "form_secret", c.FormSecret) + checkNotEmpty(configErrors, "base_url", c.BaseURL) + if len(*configErrors) > 0 { + return + } - c.TextTemplates = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError)) - c.TextTemplates = textTemplate.Must(c.TextTemplates.New("serverNoticeTemplate").Parse(c.ServerNoticeContent.Body)) + p, err := filepath.Abs(c.TemplateDir) + if err != nil { + configErrors.Add("unable to get template directory") + return + } - // Read all defined *.gohtml templates - t, err := template.ParseGlob(filepath.Join(p, "*.gohtml")) - if err != nil || t == nil { - configErrors.Add(fmt.Sprintf("unable to read consent templates: %+v", err)) - return - } - c.Templates = t - // Verify we've got a template for the defined version - versionTemplate := c.Templates.Lookup(c.Version + ".gohtml") - if versionTemplate == nil { - configErrors.Add(fmt.Sprintf("unable to load defined '%s' policy template", c.Version)) - } + c.TextTemplates = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError)) + c.TextTemplates = textTemplate.Must(c.TextTemplates.New("serverNoticeTemplate").Parse(c.ServerNoticeContent.Body)) + + // Read all defined *.gohtml templates + t, err := template.ParseGlob(filepath.Join(p, "*.gohtml")) + if err != nil || t == nil { + configErrors.Add(fmt.Sprintf("unable to read consent templates: %+v", err)) + return + } + c.Templates = t + // Verify we've got a template for the defined version + versionTemplate := c.Templates.Lookup(c.Version + ".gohtml") + if versionTemplate == nil { + configErrors.Add(fmt.Sprintf("unable to load defined '%s' policy template", c.Version)) } }