feat(goctl): Add api parser (#2585)

This commit is contained in:
anqiansong
2023-03-28 23:45:26 +08:00
committed by GitHub
parent 455a6c8f97
commit 50bc361430
59 changed files with 11633 additions and 6 deletions

View File

@@ -8,6 +8,8 @@ import (
"github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/ast"
"github.com/zeromicro/go-zero/tools/goctl/api/parser/g4/gen/api"
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
"github.com/zeromicro/go-zero/tools/goctl/pkg/env"
apiParser "github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/parser"
)
type parser struct {
@@ -17,6 +19,10 @@ type parser struct {
// Parse parses the api file
func Parse(filename string) (*spec.ApiSpec, error) {
if env.UseExperimental() {
return apiParser.Parse(filename, "")
}
astParser := ast.NewParser(ast.WithParserPrefix(filepath.Base(filename)), ast.WithParserDebug())
parsedApi, err := astParser.Parse(filename)
if err != nil {

View File

@@ -11,6 +11,11 @@
}
// service doc
@server(
group: test
middleware: m1,m2
prefix: v1
)
service greet-api {
// handler doc
@handler GreetHandler // handler comment