/
masonryutil.go
37 lines (30 loc) · 951 Bytes
/
masonryutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Copyright (C) 2018 OpenControl Contributors. See LICENSE.md for license.
*/
package masonryutil
import (
"io/ioutil"
"os"
"strings"
)
// replaceParentheses removes parenthesis in strings
func replaceParentheses(text string) string {
return strings.Replace(strings.Replace(text, "(", "", -1), ")", "", -1)
}
// replaceSpace changes whitepspace to underscore in strings
func replaceSpaceUnderscore(text string) string {
return strings.Replace(text, " ", "_", -1)
}
// FileNameHandler creates a standardized filename
func FileNameHandler(fileName string) string {
normalizedFileName := replaceParentheses(fileName)
normalizedFileName = replaceSpaceUnderscore(normalizedFileName)
return normalizedFileName
}
// FileWriter handles all file writing for Compliance Masonry
func FileWriter(filePath string, fileText []byte, filePerms os.FileMode) {
err := ioutil.WriteFile(filePath, fileText, filePerms)
if err != nil {
panic(err)
}
}