-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaffold_generate.go
56 lines (43 loc) · 1.15 KB
/
scaffold_generate.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
package main
import (
_ "embed"
)
//go:embed scaffold-template/go.mod.tmpl
var goModTmpl string
//go:embed scaffold-template/server.go.tmpl
var serverGoTmpl string
//go:embed scaffold-template/handlers/api.go.tmpl
var apiGoTmpl string
//go:embed scaffold-template/handlers/healthcheck.go
var healthcheckGo []byte
//go:embed scaffold-template/handlers/index.go.tmpl
var indexGoTmpl string
//go:embed scaffold-template/handlers/setup.go.tmpl
var setupGoTmpl string
//go:embed scaffold-template/static/css/styles.css
var stylesCss []byte
//go:embed scaffold-template/static/js/index.js
var indexJs []byte
func createScaffoldFiles(s Scaffold) error {
tmplMap := map[string]string{
"go.mod": goModTmpl,
"server.go": serverGoTmpl,
"handlers/api.go": apiGoTmpl,
"handlers/setup.go": setupGoTmpl,
}
if s.Role {
tmplMap["handlers/index.go"] = indexGoTmpl
}
err := renderToFile(s, tmplMap)
if err != nil {
return err
}
fileMap := map[string][]byte{
"handlers/healthcheck.go": healthcheckGo,
}
if s.Role {
fileMap["static/js/index.js"] = indexJs
fileMap["static/css/styles.css"] = stylesCss
}
return writeToFile(s, fileMap)
}