validate.go 466 B

12345678910111213141516171819202122232425
  1. package validate
  2. import (
  3. "errors"
  4. "fmt"
  5. "git.i2edu.net/i2/go-zero/tools/goctl/api/parser"
  6. "github.com/logrusorgru/aurora"
  7. "github.com/urfave/cli"
  8. )
  9. // GoValidateApi verifies whether the api has a syntax error
  10. func GoValidateApi(c *cli.Context) error {
  11. apiFile := c.String("api")
  12. if len(apiFile) == 0 {
  13. return errors.New("missing -api")
  14. }
  15. _, err := parser.Parse(apiFile)
  16. if err == nil {
  17. fmt.Println(aurora.Green("api format ok"))
  18. }
  19. return err
  20. }