mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
api imports take the form of relative paths (#3201)
Co-authored-by: 李春华 <lichunhua@threesoft.cn>
This commit is contained in:
parent
b1c4c4736f
commit
9fa98c2bd3
@ -19,7 +19,6 @@ type (
|
||||
linePrefix string
|
||||
debug bool
|
||||
log console.Console
|
||||
src string
|
||||
skipCheckTypeDeclaration bool
|
||||
handlerMap map[string]PlaceHolder
|
||||
routeMap map[string]PlaceHolder
|
||||
@ -88,30 +87,29 @@ func (p *Parser) Parse(filename string) (*Api, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.src = abs
|
||||
data, err := p.readContent(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.importStatck.push(p.src)
|
||||
p.importStatck.push(abs)
|
||||
return p.parse(filename, data)
|
||||
}
|
||||
|
||||
// ParseContent is used to parse the api from the specified content
|
||||
func (p *Parser) ParseContent(content string, filename ...string) (*Api, error) {
|
||||
var f string
|
||||
var f, abs string
|
||||
if len(filename) > 0 {
|
||||
f = filename[0]
|
||||
abs, err := filepath.Abs(f)
|
||||
a, err := filepath.Abs(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.src = abs
|
||||
abs = a
|
||||
}
|
||||
|
||||
p.importStatck.push(p.src)
|
||||
p.importStatck.push(abs)
|
||||
return p.parse(f, content)
|
||||
}
|
||||
|
||||
@ -127,7 +125,7 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
||||
apiAstList = append(apiAstList, root)
|
||||
p.storeVerificationInfo(root)
|
||||
p.syntax = root.Syntax
|
||||
impApiAstList, err := p.invokeImportedApi(root.Import)
|
||||
impApiAstList, err := p.invokeImportedApi(filename, root.Import)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -144,10 +142,10 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
||||
return allApi, nil
|
||||
}
|
||||
|
||||
func (p *Parser) invokeImportedApi(imports []*ImportExpr) ([]*Api, error) {
|
||||
func (p *Parser) invokeImportedApi(filename string, imports []*ImportExpr) ([]*Api, error) {
|
||||
var apiAstList []*Api
|
||||
for _, imp := range imports {
|
||||
dir := filepath.Dir(p.src)
|
||||
dir := filepath.Dir(filename)
|
||||
impPath := strings.ReplaceAll(imp.Value.Text(), "\"", "")
|
||||
if !filepath.IsAbs(impPath) {
|
||||
impPath = filepath.Join(dir, impPath)
|
||||
@ -178,7 +176,7 @@ func (p *Parser) invokeImportedApi(imports []*ImportExpr) ([]*Api, error) {
|
||||
}
|
||||
p.storeVerificationInfo(nestedApi)
|
||||
apiAstList = append(apiAstList, nestedApi)
|
||||
list, err := p.invokeImportedApi(nestedApi.Import)
|
||||
list, err := p.invokeImportedApi(impPath, nestedApi.Import)
|
||||
p.importStatck.pop()
|
||||
apiAstList = append(apiAstList, list...)
|
||||
|
||||
|
@ -114,7 +114,7 @@ func primitiveType(tp string) (string, bool) {
|
||||
switch tp {
|
||||
case "string":
|
||||
return "string", true
|
||||
case "int", "int8", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64":
|
||||
case "int", "int8","int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64":
|
||||
return "number", true
|
||||
case "float", "float32", "float64":
|
||||
return "number", true
|
||||
|
Loading…
Reference in New Issue
Block a user