123456789101112131415161718192021222324252627282930313233343536373839 |
- package generator
- import (
- _ "embed"
- "fmt"
- "path/filepath"
- "strings"
- conf "github.com/zeromicro/go-zero/tools/goctl/config"
- "github.com/zeromicro/go-zero/tools/goctl/rpc/parser"
- "github.com/zeromicro/go-zero/tools/goctl/util"
- "github.com/zeromicro/go-zero/tools/goctl/util/format"
- "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
- "github.com/zeromicro/go-zero/tools/goctl/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) 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)
- }
|