-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathutils.go
More file actions
46 lines (37 loc) · 912 Bytes
/
utils.go
File metadata and controls
46 lines (37 loc) · 912 Bytes
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
38
39
40
41
42
43
44
45
46
package main
import (
"math/rand"
"os"
"path/filepath"
"strings"
"unicode"
)
func generateRandomString() string {
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
const length = 8
result := make([]byte, length)
for i := range result {
result[i] = charset[rand.Intn(len(charset))]
}
return string(result)
}
func convertToUnknownType(typeName string) string {
var result strings.Builder
result.WriteString("UNKNOWN_")
for i, r := range typeName {
if i > 0 && unicode.IsUpper(r) && !unicode.IsUpper(rune(typeName[i-1])) {
result.WriteRune('_')
}
result.WriteRune(unicode.ToUpper(r))
}
return result.String()
}
func writeFile(fileContent []byte, fileName string) error {
// Create all necessary directories
dir := filepath.Dir(fileName)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
// Write the file
return os.WriteFile(fileName, fileContent, 0644)
}