2019-01-29 12:27:42 -05:00
|
|
|
package common
|
|
|
|
|
2019-01-29 13:24:26 -05:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"html/template"
|
|
|
|
)
|
2019-01-29 12:27:42 -05:00
|
|
|
|
|
|
|
func isalphanumeric(b byte) bool {
|
|
|
|
if '0' <= b && b <= '9' {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if 'a' <= b && b <= 'z' {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if 'A' <= b && b <= 'Z' {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-04-05 16:39:00 -04:00
|
|
|
func templateCleanResourceName(s string) string {
|
2019-01-29 12:27:42 -05:00
|
|
|
allowed := []byte{'(', ')', '[', ']', ' ', '.', '/', '-', '\'', '@', '_'}
|
|
|
|
b := []byte(s)
|
|
|
|
newb := make([]byte, len(b))
|
|
|
|
for i, c := range b {
|
|
|
|
if isalphanumeric(c) || bytes.IndexByte(allowed, c) != -1 {
|
|
|
|
newb[i] = c
|
|
|
|
} else {
|
|
|
|
newb[i] = '-'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string(newb[:])
|
|
|
|
}
|
2019-01-29 13:24:26 -05:00
|
|
|
|
|
|
|
var TemplateFuncs = template.FuncMap{
|
2019-04-05 16:39:00 -04:00
|
|
|
"clean_resource_name": templateCleanResourceName,
|
2019-01-29 13:24:26 -05:00
|
|
|
}
|