-
Notifications
You must be signed in to change notification settings - Fork 0
/
genetc.go
41 lines (34 loc) · 1.18 KB
/
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
package generator
import (
_ "embed"
"fmt"
"path/filepath"
"strings"
conf "github.com/zhangbao138208/goctls/config"
"github.com/zhangbao138208/goctls/rpc/parser"
"github.com/zhangbao138208/goctls/util"
"github.com/zhangbao138208/goctls/util/format"
"github.com/zhangbao138208/goctls/util/pathx"
"github.com/zhangbao138208/goctls/util/stringx"
)
//go:embed etc.tpl
var etcTemplate string
// GenEtc generates the yaml configuration file of the rpc service,
// including host, port monitoring configuration items and etcd configuration
func (g *Generator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error {
dir := ctx.GetEtc()
etcFilename, err := format.FileNamingFormat(cfg.NamingFormat, ctx.GetServiceName().Source())
if err != nil {
return err
}
fileName := filepath.Join(dir.Filename, fmt.Sprintf("%v.yaml", etcFilename))
text, err := pathx.LoadTemplate(category, etcTemplateFileFile, etcTemplate)
if err != nil {
return err
}
return util.With("etc").Parse(text).SaveTo(map[string]any{
"serviceName": strings.ToLower(stringx.From(ctx.GetServiceName().Source()).ToCamel()),
"isEnt": c.Ent,
"port": c.Port,
}, fileName, false)
}