gen.go 736 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dartgen
  2. import (
  3. "errors"
  4. "strings"
  5. "git.i2edu.net/i2/go-zero/core/logx"
  6. "git.i2edu.net/i2/go-zero/tools/goctl/api/parser"
  7. "github.com/urfave/cli"
  8. )
  9. // DartCommand create dart network request code
  10. func DartCommand(c *cli.Context) error {
  11. apiFile := c.String("api")
  12. dir := c.String("dir")
  13. if len(apiFile) == 0 {
  14. return errors.New("missing -api")
  15. }
  16. if len(dir) == 0 {
  17. return errors.New("missing -dir")
  18. }
  19. api, err := parser.Parse(apiFile)
  20. if err != nil {
  21. return err
  22. }
  23. if !strings.HasSuffix(dir, "/") {
  24. dir = dir + "/"
  25. }
  26. api.Info.Title = strings.Replace(apiFile, ".api", "", -1)
  27. logx.Must(genData(dir+"data/", api))
  28. logx.Must(genApi(dir+"api/", api))
  29. logx.Must(genVars(dir + "vars/"))
  30. return nil
  31. }