genconfig.go 702 B

12345678910111213141516171819202122232425262728293031323334
  1. package generator
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
  7. "github.com/tal-tech/go-zero/tools/goctl/util"
  8. )
  9. const configTemplate = `package config
  10. import "github.com/tal-tech/go-zero/zrpc"
  11. type Config struct {
  12. zrpc.RpcServerConf
  13. }
  14. `
  15. func (g *defaultGenerator) GenConfig(ctx DirContext, _ parser.Proto) error {
  16. dir := ctx.GetConfig()
  17. fileName := filepath.Join(dir.Filename, formatFilename("config")+".go")
  18. if util.FileExists(fileName) {
  19. return nil
  20. }
  21. text, err := util.LoadTemplate(category, configTemplateFileFile, configTemplate)
  22. if err != nil {
  23. return err
  24. }
  25. return ioutil.WriteFile(fileName, []byte(text), os.ModePerm)
  26. }