genetc.go 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package gogen
  2. import (
  3. "fmt"
  4. "strconv"
  5. "git.i2edu.net/i2/go-zero/tools/goctl/api/spec"
  6. "git.i2edu.net/i2/go-zero/tools/goctl/config"
  7. "git.i2edu.net/i2/go-zero/tools/goctl/util/format"
  8. )
  9. const (
  10. defaultPort = 8888
  11. etcDir = "etc"
  12. etcTemplate = `Name: {{.serviceName}}
  13. Host: {{.host}}
  14. Port: {{.port}}
  15. `
  16. )
  17. func genEtc(dir string, cfg *config.Config, api *spec.ApiSpec) error {
  18. filename, err := format.FileNamingFormat(cfg.NamingFormat, api.Service.Name)
  19. if err != nil {
  20. return err
  21. }
  22. service := api.Service
  23. host := "0.0.0.0"
  24. port := strconv.Itoa(defaultPort)
  25. return genFile(fileGenConfig{
  26. dir: dir,
  27. subdir: etcDir,
  28. filename: fmt.Sprintf("%s.yaml", filename),
  29. templateName: "etcTemplate",
  30. category: category,
  31. templateFile: etcTemplateFile,
  32. builtinTemplate: etcTemplate,
  33. data: map[string]string{
  34. "serviceName": service.Name,
  35. "host": host,
  36. "port": port,
  37. },
  38. })
  39. }