-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
321 additions
and
138 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
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
57 changes: 57 additions & 0 deletions
57
cmd/gf/internal/cmd/genctrl/genctrl_generate_ctrl_clear.go
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,57 @@ | ||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved. | ||
// | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, | ||
// You can obtain one at https://github.com/gogf/gf. | ||
|
||
package genctrl | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog" | ||
"github.com/gogf/gf/v2/os/gfile" | ||
"github.com/gogf/gf/v2/text/gregex" | ||
"github.com/gogf/gf/v2/text/gstr" | ||
) | ||
|
||
type controllerClearer struct{} | ||
|
||
func newControllerClearer() *controllerClearer { | ||
return &controllerClearer{} | ||
} | ||
|
||
func (c *controllerClearer) Clear(dstModuleFolderPath string, extraApiItemsInCtrl []apiItem) (err error) { | ||
for _, item := range extraApiItemsInCtrl { | ||
if err = c.doClear(dstModuleFolderPath, item); err != nil { | ||
return err | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (c *controllerClearer) doClear(dstModuleFolderPath string, item apiItem) (err error) { | ||
var ( | ||
methodNameSnake = gstr.CaseSnake(item.MethodName) | ||
methodFilePath = gfile.Join(dstModuleFolderPath, fmt.Sprintf( | ||
`%s_%s_%s.go`, item.Module, item.Version, methodNameSnake, | ||
)) | ||
fileContent = gstr.Trim(gfile.GetContents(methodFilePath)) | ||
) | ||
match, err := gregex.MatchString(`.+?Req.+?Res.+?{([\s\S]+?)}`, fileContent) | ||
if err != nil { | ||
return err | ||
} | ||
if len(match) > 1 { | ||
implements := gstr.Trim(match[1]) | ||
// One line. | ||
if !gstr.Contains(implements, "\n") && gstr.Contains(implements, `CodeNotImplemented`) { | ||
mlog.Printf( | ||
`remove unimplemented and of no api definitions controller file: %s`, | ||
methodFilePath, | ||
) | ||
err = gfile.Remove(methodFilePath) | ||
} | ||
} | ||
return | ||
} |
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
Oops, something went wrong.