packer-cn/builder/googlecompute/template_funcs.go
Megan Marsh 6c704f7046 Revert "fix template imports"
This reverts commit 0e70e0e5a4c570790f7f253e69c6e09ed18e38d1.
2019-11-04 14:29:00 -08:00

39 lines
688 B
Go

package googlecompute
import (
"strings"
"text/template"
)
func isalphanumeric(b byte) bool {
if '0' <= b && b <= '9' {
return true
}
if 'a' <= b && b <= 'z' {
return true
}
return false
}
// Clean up image name by replacing invalid characters with "-"
// and converting upper cases to lower cases
func templateCleanImageName(s string) string {
if validImageName.MatchString(s) {
return s
}
b := []byte(strings.ToLower(s))
newb := make([]byte, len(b))
for i := range newb {
if isalphanumeric(b[i]) {
newb[i] = b[i]
} else {
newb[i] = '-'
}
}
return string(newb)
}
var TemplateFuncs = template.FuncMap{
"clean_resource_name": templateCleanImageName,
}