From 7623c7569b7a9be7e7f233590e8ac1e652bd7e3a Mon Sep 17 00:00:00 2001 From: Justin SB Date: Mon, 11 Nov 2019 17:32:09 -0500 Subject: [PATCH] Don't rewrite potentially shared values Make them constant and use a local var. --- pkg/scaffold/v2/webhook/webhook.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/scaffold/v2/webhook/webhook.go b/pkg/scaffold/v2/webhook/webhook.go index 6abba0417c9..65e32d3dfd9 100644 --- a/pkg/scaffold/v2/webhook/webhook.go +++ b/pkg/scaffold/v2/webhook/webhook.go @@ -68,14 +68,15 @@ func (a *Webhook) GetInput() (input.Input, error) { a.Path = filepath.Join("api", a.Resource.Version, fmt.Sprintf("%s_webhook.go", strings.ToLower(a.Resource.Kind))) } + webhookTemplate := WebhookTemplate if a.Defaulting { - WebhookTemplate = WebhookTemplate + DefaultingWebhookTemplate + webhookTemplate = webhookTemplate + DefaultingWebhookTemplate } if a.Validating { - WebhookTemplate = WebhookTemplate + ValidatingWebhookTemplate + webhookTemplate = webhookTemplate + ValidatingWebhookTemplate } - a.TemplateBody = WebhookTemplate + a.TemplateBody = webhookTemplate a.Input.IfExistsAction = input.Error return a.Input, nil } @@ -85,7 +86,7 @@ func (g *Webhook) Validate() error { return g.Resource.Validate() } -var ( +const ( WebhookTemplate = `{{ .Boilerplate }} package {{ .Resource.Version }}