diff --git a/cmd/gf/internal/cmd/cmd_gen_service.go b/cmd/gf/internal/cmd/cmd_gen_service.go index ab995b71f..e021102f0 100644 --- a/cmd/gf/internal/cmd/cmd_gen_service.go +++ b/cmd/gf/internal/cmd/cmd_gen_service.go @@ -171,11 +171,7 @@ func (c cGenService) Service(ctx context.Context, in cGenServiceInput) (out *cGe } } - // Go imports updating. - mlog.Printf(`goimports go files in "%s", it may take seconds...`, in.DstFolder) - utils.GoImports(in.DstFolder) - - // Replica v1 to v2 for GoFrame. + // Replace v1 to v2 for GoFrame. if err = c.replaceGeneratedServiceContentGFV2(in); err != nil { return nil, err } diff --git a/cmd/gf/internal/utility/utils/utils.go b/cmd/gf/internal/utility/utils/utils.go index 770b74fa0..831326242 100644 --- a/cmd/gf/internal/utility/utils/utils.go +++ b/cmd/gf/internal/utility/utils/utils.go @@ -10,18 +10,11 @@ import ( // GoFmt formats the source file. func GoFmt(path string) { - if err := pretty(path, true); err != nil { + if err := doGoFmt(path, true); err != nil { mlog.Fatalf(`error format "%s" go files: %v`, path, err) } } -// GoImports adds or removes import statements as necessary for the source file. -func GoImports(path string) { - if err := pretty(path); err != nil { - mlog.Fatalf(`error update "%s" go file imports: %v`, path, err) - } -} - // IsFileDoNotEdit checks and returns whether file contains `do not edit` key. func IsFileDoNotEdit(filePath string) bool { if !gfile.Exists(filePath) { @@ -30,8 +23,8 @@ func IsFileDoNotEdit(filePath string) bool { return gstr.Contains(gfile.GetContents(filePath), consts.DoNotEditKey) } -// pretty format go file and adds or removes import statements as necessary. -func pretty(filePath string, formatOnly ...bool) error { +// doGoFmt format go file and adds or removes import statements as necessary. +func doGoFmt(path string, formatOnly ...bool) error { var genOpt *imports.Options if len(formatOnly) > 0 { genOpt = &imports.Options{ @@ -49,11 +42,13 @@ func pretty(filePath string, formatOnly ...bool) error { } return string(res) } - if gfile.IsFile(filePath) { - if gfile.ExtName(filePath) != "go" { + // File format. + if gfile.IsFile(path) { + if gfile.ExtName(path) != "go" { return nil } - return gfile.ReplaceFileFunc(replaceFunc, filePath) + return gfile.ReplaceFileFunc(replaceFunc, path) } - return gfile.ReplaceDirFunc(replaceFunc, filePath, "*.go", true) + // Folder format. + return gfile.ReplaceDirFunc(replaceFunc, path, "*.go", true) }