-
Notifications
You must be signed in to change notification settings - Fork 1
/
genetc.go
executable file
·43 lines (36 loc) · 1.27 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
42
43
package generator
import (
"fmt"
"path/filepath"
"strings"
conf "github.com/shuguocloud/go-zero/tools/goctl/config"
"github.com/shuguocloud/go-zero/tools/goctl/rpc/parser"
"github.com/shuguocloud/go-zero/tools/goctl/util"
"github.com/shuguocloud/go-zero/tools/goctl/util/format"
"github.com/shuguocloud/go-zero/tools/goctl/util/pathx"
"github.com/shuguocloud/go-zero/tools/goctl/util/stringx"
)
const etcTemplate = `Name: {{.serviceName}}.rpc
ListenOn: 127.0.0.1:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: {{.serviceName}}.rpc
`
// GenEtc generates the yaml configuration file of the rpc service,
// including host, port monitoring configuration items and etcd configuration
func (g *DefaultGenerator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config) 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]interface{}{
"serviceName": strings.ToLower(stringx.From(ctx.GetServiceName().Source()).ToCamel()),
}, fileName, false)
}