From 2f0e1218dcfc221e4cfc117fe4909a58c7506e87 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Fri, 13 May 2016 15:37:25 -0700 Subject: [PATCH] Move regexp to package scope so it will be validated by the compiler instead of at runtime --- builder/googlecompute/config.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 981a60a98..e93347087 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -14,6 +14,8 @@ import ( "github.com/mitchellh/packer/template/interpolate" ) +var reImageFamily = regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`) + // Config is the configuration structure for the GCE builder. It stores // both the publicly settable state as well as the privately generated // state of the config object. @@ -101,7 +103,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } if c.ImageFamily != "" { - if !regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`).MatchString(c.ImageFamily) { + if !reImageFamily.MatchString(c.ImageFamily) { errs = packer.MultiErrorAppend(errs, errors.New("Invalid image family: The first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash")) }