Skip to content

Commit

Permalink
fix issue #2734 (#2740)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Jul 5, 2023
1 parent ba2a7e4 commit c90e931
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/gf/internal/cmd/genservice/genservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,21 @@ func (c CGenService) checkAndUpdateMain(srcFolder string) (err error) {
mainFilePath = gfile.Join(gfile.Dir(gfile.Dir(gfile.Dir(logicFilePath))), "main.go")
mainFileContent = gfile.GetContents(mainFilePath)
)
// No main content found.
if mainFileContent == "" {
return nil
}
if gstr.Contains(mainFileContent, importStr) {
return nil
}
match, err := gregex.MatchString(`import \(([\s\S]+?)\)`, mainFileContent)
if err != nil {
return err
}
// No match.
if len(match) < 2 {
return nil
}
lines := garray.NewStrArrayFrom(gstr.Split(match[1], "\n"))
for i, line := range lines.Slice() {
line = gstr.Trim(line)
Expand Down

0 comments on commit c90e931

Please sign in to comment.