forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genetc.go
45 lines (38 loc) · 967 Bytes
/
genetc.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
package gogen
import (
_ "embed"
"fmt"
"strconv"
"github.com/mikokutou1/go-zero-m/tools/goctl/api/spec"
"github.com/mikokutou1/go-zero-m/tools/goctl/config"
"github.com/mikokutou1/go-zero-m/tools/goctl/util/format"
)
const (
defaultPort = 8888
etcDir = "etc"
)
//go:embed etc.tpl
var etcTemplate string
func genEtc(dir string, cfg *config.Config, api *spec.ApiSpec) error {
filename, err := format.FileNamingFormat(cfg.NamingFormat, api.Service.Name)
if err != nil {
return err
}
service := api.Service
host := "0.0.0.0"
port := strconv.Itoa(defaultPort)
return genFile(fileGenConfig{
dir: dir,
subdir: etcDir,
filename: fmt.Sprintf("%s.yaml", filename),
templateName: "etcTemplate",
category: category,
templateFile: etcTemplateFile,
builtinTemplate: etcTemplate,
data: map[string]string{
"serviceName": service.Name,
"host": host,
"port": port,
},
})
}