go-zero/tools/goctl/api/validate/validate.go

34 lines
601 B
Go
Raw Normal View History

2020-07-29 17:11:41 +08:00
package validate
import (
"errors"
"fmt"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"github.com/zeromicro/go-zero/tools/goctl/api/parser"
2020-07-29 17:11:41 +08:00
)
// VarStringAPI describes an API.
var VarStringAPI string
// GoValidateApi verifies whether the api has a syntax error
func GoValidateApi(_ *cobra.Command, _ []string) error {
apiFile := VarStringAPI
2020-07-29 17:11:41 +08:00
if len(apiFile) == 0 {
return errors.New("missing -api")
}
spec, err := parser.Parse(apiFile)
if err != nil {
return err
}
err = spec.Validate()
2020-07-29 17:11:41 +08:00
if err == nil {
fmt.Println(aurora.Green("api format ok"))
}
return err
}