-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
executable file
·55 lines (44 loc) · 1.01 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"go/printer"
"log"
"os"
"regexp"
)
func replaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string {
result := ""
lastIndex := 0
for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
var groups []string
for i := 0; i < len(v); i += 2 {
groups = append(groups, str[v[i]:v[i+1]])
}
result += str[lastIndex:v[0]] + repl(groups)
lastIndex = v[1]
}
return result + str[lastIndex:]
}
func main() {
dingoYMLPath := "dingo.yml"
outputFile := "dingo.go"
file, err := ParseYAMLFile(dingoYMLPath)
if err != nil {
log.Fatalln(err)
}
packageName := file.Package
if packageName == "" {
packageName = file.getPackageName(dingoYMLPath)
}
file, err = GenerateContainer(file, packageName, outputFile)
if err != nil {
log.Fatalln(err)
}
outFile, err := os.Create(outputFile)
if err != nil {
log.Fatalln("open file:", err)
}
err = printer.Fprint(outFile, file.fset, file.file)
if err != nil {
log.Fatalln("writer:", err)
}
}