Skip to content

Commit 7623c75

Browse files
committed
Don't rewrite potentially shared values
Make them constant and use a local var.
1 parent e6a5211 commit 7623c75

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/scaffold/v2/webhook/webhook.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ func (a *Webhook) GetInput() (input.Input, error) {
6868
a.Path = filepath.Join("api", a.Resource.Version,
6969
fmt.Sprintf("%s_webhook.go", strings.ToLower(a.Resource.Kind)))
7070
}
71+
webhookTemplate := WebhookTemplate
7172
if a.Defaulting {
72-
WebhookTemplate = WebhookTemplate + DefaultingWebhookTemplate
73+
webhookTemplate = webhookTemplate + DefaultingWebhookTemplate
7374
}
7475
if a.Validating {
75-
WebhookTemplate = WebhookTemplate + ValidatingWebhookTemplate
76+
webhookTemplate = webhookTemplate + ValidatingWebhookTemplate
7677
}
7778

78-
a.TemplateBody = WebhookTemplate
79+
a.TemplateBody = webhookTemplate
7980
a.Input.IfExistsAction = input.Error
8081
return a.Input, nil
8182
}
@@ -85,7 +86,7 @@ func (g *Webhook) Validate() error {
8586
return g.Resource.Validate()
8687
}
8788

88-
var (
89+
const (
8990
WebhookTemplate = `{{ .Boilerplate }}
9091
9192
package {{ .Resource.Version }}

0 commit comments

Comments
 (0)