gomod.go 451 B

12345678910111213141516171819202122
  1. package gen
  2. import (
  3. "fmt"
  4. "github.com/tal-tech/go-zero/core/logx"
  5. "github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
  6. )
  7. func (g *defaultRpcGenerator) initGoMod() error {
  8. if !g.Ctx.IsInGoEnv {
  9. projectDir := g.dirM[dirTarget]
  10. cmd := fmt.Sprintf("go mod init %s", g.Ctx.ProjectName.Source())
  11. output, err := execx.Run(fmt.Sprintf(cmd), projectDir)
  12. if err != nil {
  13. logx.Error(err)
  14. return err
  15. }
  16. g.Ctx.Info(output)
  17. }
  18. return nil
  19. }