-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (54 loc) · 1.27 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
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"text/template"
)
// type Data struct {
// Function string `json:"function"`
// Request string `json:"request"`
// }
type Data struct {
DefinitionRepository string `json:"DefinitionRepository"`
DefinitionServiceserver string `json:"DefinitionServiceserver"`
DefinitionRPC string `json:"DefinitionRPC"`
UsecaseFunction string `json:"UsecaseFunction"`
}
func main() {
inputDir := "inputs/"
inputFile := "sample_server.json"
inputPath := inputDir + inputFile
jsonBody, err := ioutil.ReadFile(inputPath)
if err != nil {
log.Fatal(err)
}
var data Data
if err := json.Unmarshal(jsonBody, &data); err != nil {
log.Fatal(err)
}
templateDir := "templates/"
templateFile := "server.tmpl"
templatePath := templateDir + templateFile
t, err := template.New(templateFile).ParseFiles(templatePath)
if err != nil {
log.Fatal(err)
}
outputDir := "outputs/hoge/"
outputFile := "hoge.go"
outputPath := outputDir + outputFile
if _, err := os.Stat(outputDir); os.IsNotExist(err) {
err := os.Mkdir(outputDir, 0777)
if err != nil {
log.Fatal(err)
}
}
f, err := os.Create(outputPath)
if err != nil {
log.Fatal(err)
}
if err = t.Execute(f, data); err != nil {
log.Fatal(err)
}
}