go-zero/tools/goctl/api/validate/validate.go
anqiansong 305587aa81
fix: Fix issue #1810 (#1811)
* Fix #1810

* Remove go embed

* Format code

* Remove useless code

Co-authored-by: anqiansong <anqiansong@bytedance.com>
2022-04-21 15:22:43 +08:00

31 lines
530 B
Go

package validate
import (
"errors"
"fmt"
"github.com/logrusorgru/aurora"
"github.com/urfave/cli"
"github.com/zeromicro/go-zero/tools/goctl/api/parser"
)
// GoValidateApi verifies whether the api has a syntax error
func GoValidateApi(c *cli.Context) error {
apiFile := c.String("api")
if len(apiFile) == 0 {
return errors.New("missing -api")
}
spec, err := parser.Parse(apiFile)
if err != nil {
return err
}
err = spec.Validate()
if err == nil {
fmt.Println(aurora.Green("api format ok"))
}
return err
}