defaultgenerator.go 799 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package generator
  2. import (
  3. "os/exec"
  4. "github.com/tal-tech/go-zero/tools/goctl/util/console"
  5. )
  6. // DefaultGenerator defines the environment needs of rpc service generation
  7. type DefaultGenerator struct {
  8. log console.Console
  9. }
  10. // NewDefaultGenerator returns an instance of DefaultGenerator
  11. func NewDefaultGenerator() *DefaultGenerator {
  12. log := console.NewColorConsole()
  13. return &DefaultGenerator{
  14. log: log,
  15. }
  16. }
  17. // Prepare provides environment detection generated by rpc service,
  18. // including go environment, protoc, whether protoc-gen-go is installed or not
  19. func (g *DefaultGenerator) Prepare() error {
  20. _, err := exec.LookPath("go")
  21. if err != nil {
  22. return err
  23. }
  24. _, err = exec.LookPath("protoc")
  25. if err != nil {
  26. return err
  27. }
  28. _, err = exec.LookPath("protoc-gen-go")
  29. return err
  30. }