forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(goctl:) fix circle import in case new parser (zeromicro#3750)
Co-authored-by: Kevin Wan <[email protected]>
- Loading branch information
Showing
4 changed files
with
72 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package importstack | ||
|
||
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 New() *ImportStack { | ||
return &ImportStack{} | ||
} | ||
|
||
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] | ||
} | ||
|
||
func (s *ImportStack) List() []string { | ||
return *s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters