-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.go
42 lines (33 loc) · 821 Bytes
/
util.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
38
39
40
41
42
package main
import (
"os"
"strings"
)
const id = "ID"
func snake2Camel(word string) string {
// ID should be always uppercas
words := strings.Split(word, "_")
for i, w := range words {
if strings.ToLower(w) == strings.ToLower(id) {
words[i] = strings.ToUpper(id)
}
}
return strings.Replace(strings.Title(strings.Join(words, " ")), " ", "", -1)
}
func snake2CamelLower(word string) string {
words := strings.Split(word, "_")
return words[0] + strings.ReplaceAll(strings.Title(strings.Join(words[1:], " ")), " ", "")
}
func saveToFile(name string, b []byte) error {
f, err := os.OpenFile(name+".go", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
return err
}
if _, err := f.Write(b); err != nil {
return err
}
if err := f.Close(); err != nil {
return err
}
return nil
}