feat(goctl): supports api multi-level importing (#1747)
* feat(goctl): supports api multi-level importing Resolves: #1744 * fix(goctl): import-cycle, etc. import-cycle will not be allowed e.g., a.api -> b.api -> a.api regular multiple-import will be allowed e.g., a.api -> b.api -> c.api -> c.api * refactor(goctl): adds comments to exported var * fix(goctl): typo in a comment
This commit is contained in:
23
tools/goctl/api/parser/g4/ast/importstack.go
Normal file
23
tools/goctl/api/parser/g4/ast/importstack.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package ast
|
||||
|
||||
import "errors"
|
||||
|
||||
// ErrImportCycleNotAllowed defines an error for circular importing
|
||||
var ErrImportCycleNotAllowed = errors.New("import cycle not allowed")
|
||||
|
||||
// importStack a stack of import paths
|
||||
type importStack []string
|
||||
|
||||
func (s *importStack) push(p string) error {
|
||||
for _, x := range *s {
|
||||
if x == p {
|
||||
return ErrImportCycleNotAllowed
|
||||
}
|
||||
}
|
||||
*s = append(*s, p)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *importStack) pop() {
|
||||
*s = (*s)[0 : len(*s)-1]
|
||||
}
|
||||
Reference in New Issue
Block a user