go-zero/tools/goctl/rpc/gen/genetc.go

34 lines
689 B
Go
Raw Normal View History

package gen
2020-08-28 21:22:35 +08:00
import (
"fmt"
"path/filepath"
"github.com/tal-tech/go-zero/tools/goctl/util"
)
const etcTemplate = `Name: {{.serviceName}}.rpc
ListenOn: 127.0.0.1:8080
Etcd:
Hosts:
2020-08-29 20:27:52 +08:00
- 127.0.0.1:2379
2020-08-28 21:22:35 +08:00
Key: {{.serviceName}}.rpc
`
func (g *defaultRpcGenerator) genEtc() error {
etdDir := g.dirM[dirEtc]
fileName := filepath.Join(etdDir, fmt.Sprintf("%v.yaml", g.Ctx.ServiceName.Lower()))
if util.FileExists(fileName) {
return nil
}
text, err := util.LoadTemplate(category, etcTemplateFileFile, etcTemplate)
if err != nil {
return err
}
return util.With("etc").Parse(text).SaveTo(map[string]interface{}{
2020-08-28 21:22:35 +08:00
"serviceName": g.Ctx.ServiceName.Lower(),
}, fileName, false)
}