genetc.go 586 B

12345678910111213141516171819202122232425262728
  1. package gen
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "github.com/tal-tech/go-zero/tools/goctl/util"
  6. )
  7. const etcTemplate = `Name: {{.serviceName}}.rpc
  8. ListenOn: 127.0.0.1:8080
  9. Etcd:
  10. Hosts:
  11. - 127.0.0.1:2379
  12. Key: {{.serviceName}}.rpc
  13. `
  14. func (g *defaultRpcGenerator) genEtc() error {
  15. etdDir := g.dirM[dirEtc]
  16. fileName := filepath.Join(etdDir, fmt.Sprintf("%v.yaml", g.Ctx.ServiceName.Lower()))
  17. if util.FileExists(fileName) {
  18. return nil
  19. }
  20. return util.With("etc").Parse(etcTemplate).SaveTo(map[string]interface{}{
  21. "serviceName": g.Ctx.ServiceName.Lower(),
  22. }, fileName, false)
  23. }