generator.go 936 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package generator
  2. import (
  3. "log"
  4. conf "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/config"
  5. "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/env"
  6. "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/util/console"
  7. )
  8. // Generator defines the environment needs of rpc service generation
  9. type Generator struct {
  10. log console.Console
  11. cfg *conf.Config
  12. verbose bool
  13. }
  14. // NewGenerator returns an instance of Generator
  15. func NewGenerator(style string, verbose bool) *Generator {
  16. cfg, err := conf.NewConfig(style)
  17. if err != nil {
  18. log.Fatalln(err)
  19. }
  20. colorLogger := console.NewColorConsole(verbose)
  21. return &Generator{
  22. log: colorLogger,
  23. cfg: cfg,
  24. verbose: verbose,
  25. }
  26. }
  27. // Prepare provides environment detection generated by rpc service,
  28. // including go environment, protoc, whether protoc-gen-go is installed or not
  29. func (g *Generator) Prepare() error {
  30. return env.Prepare(true, true, g.verbose)
  31. }