-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
58 lines (49 loc) · 1020 Bytes
/
json.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
// Package generate implements of generate files for command needs
package generate
import (
"fmt"
"html/template"
"os"
"path/filepath"
)
// Generate json file
// Accepts projectName, database and httpFramework as string
// Returns error
func GenerateJsonFile(projectName, database, httpFramework string, useOrm bool) error {
filename := "gig.json"
fullPath := filepath.Join(projectName, filename)
if _, err := os.Stat(fullPath); !os.IsNotExist(err) {
return err
}
f, err := os.Create(fullPath)
if err != nil {
return err
}
defer f.Close()
var tmplString = fmt.Sprintf(
`{
"version": "1",
"name": "%s",
"database": "%s",
"http_framework": "%s",
"use_orm": %t
}`,
projectName,
database,
httpFramework,
useOrm,
)
type tmplVars struct {
Version string
CamelName string
}
vars := tmplVars{
Version: "1",
CamelName: filename,
}
tmpl := template.Must(template.New("gig").Parse(tmplString))
if err := tmpl.Execute(f, vars); err != nil {
return err
}
return nil
}