diff --git a/cmd/kratos/internal/base/path.go b/cmd/kratos/internal/base/path.go index 7456ba67a..d24647fd3 100644 --- a/cmd/kratos/internal/base/path.go +++ b/cmd/kratos/internal/base/path.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "os" - "path" "path/filepath" "strings" @@ -17,7 +16,7 @@ func kratosHome() string { if err != nil { log.Fatal(err) } - home := path.Join(dir, ".kratos") + home := filepath.Join(dir, ".kratos") if _, err := os.Stat(home); os.IsNotExist(err) { if err := os.MkdirAll(home, 0o700); err != nil { log.Fatal(err) @@ -27,7 +26,7 @@ func kratosHome() string { } func kratosHomeWithDir(dir string) string { - home := path.Join(kratosHome(), dir) + home := filepath.Join(kratosHome(), dir) if _, err := os.Stat(home); os.IsNotExist(err) { if err := os.MkdirAll(home, 0o700); err != nil { log.Fatal(err) @@ -75,8 +74,8 @@ func copyDir(src, dst string, replaces, ignores []string) error { if hasSets(fd.Name(), ignores) { continue } - srcfp := path.Join(src, fd.Name()) - dstfp := path.Join(dst, fd.Name()) + srcfp := filepath.Join(src, fd.Name()) + dstfp := filepath.Join(dst, fd.Name()) var e error if fd.IsDir() { e = copyDir(srcfp, dstfp, replaces, ignores) diff --git a/cmd/kratos/internal/base/repo.go b/cmd/kratos/internal/base/repo.go index 4ad241c89..fe1ba18e7 100644 --- a/cmd/kratos/internal/base/repo.go +++ b/cmd/kratos/internal/base/repo.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strings" ) @@ -104,7 +105,7 @@ func (r *Repo) CopyTo(ctx context.Context, to string, modPath string, ignores [] if err := r.Clone(ctx); err != nil { return err } - mod, err := ModulePath(path.Join(r.Path(), "go.mod")) + mod, err := ModulePath(filepath.Join(r.Path(), "go.mod")) if err != nil { return err } @@ -116,7 +117,7 @@ func (r *Repo) CopyToV2(ctx context.Context, to string, modPath string, ignores, if err := r.Clone(ctx); err != nil { return err } - mod, err := ModulePath(path.Join(r.Path(), "go.mod")) + mod, err := ModulePath(filepath.Join(r.Path(), "go.mod")) if err != nil { return err } diff --git a/cmd/kratos/internal/project/add.go b/cmd/kratos/internal/project/add.go index 72a89f299..df5eff110 100644 --- a/cmd/kratos/internal/project/add.go +++ b/cmd/kratos/internal/project/add.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - "path" + "path/filepath" "github.com/AlecAivazis/survey/v2" "github.com/fatih/color" @@ -17,7 +17,7 @@ var repoAddIgnores = []string{ } func (p *Project) Add(ctx context.Context, dir string, layout string, branch string, mod string) error { - to := path.Join(dir, p.Name) + to := filepath.Join(dir, p.Name) if _, err := os.Stat(to); !os.IsNotExist(err) { fmt.Printf("🚫 %s already exists\n", p.Name) @@ -40,13 +40,13 @@ func (p *Project) Add(ctx context.Context, dir string, layout string, branch str repo := base.NewRepo(layout, branch) - if err := repo.CopyToV2(ctx, to, path.Join(mod, p.Path), repoAddIgnores, []string{path.Join(p.Path, "api"), "api"}); err != nil { + if err := repo.CopyToV2(ctx, to, filepath.Join(mod, p.Path), repoAddIgnores, []string{filepath.Join(p.Path, "api"), "api"}); err != nil { return err } e := os.Rename( - path.Join(to, "cmd", "server"), - path.Join(to, "cmd", p.Name), + filepath.Join(to, "cmd", "server"), + filepath.Join(to, "cmd", p.Name), ) if e != nil { return e diff --git a/cmd/kratos/internal/project/new.go b/cmd/kratos/internal/project/new.go index c084e7f0e..73c01986c 100644 --- a/cmd/kratos/internal/project/new.go +++ b/cmd/kratos/internal/project/new.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - "path" + "path/filepath" "github.com/AlecAivazis/survey/v2" "github.com/fatih/color" @@ -20,7 +20,7 @@ type Project struct { // New new a project from remote repo. func (p *Project) New(ctx context.Context, dir string, layout string, branch string) error { - to := path.Join(dir, p.Name) + to := filepath.Join(dir, p.Name) if _, err := os.Stat(to); !os.IsNotExist(err) { fmt.Printf("🚫 %s already exists\n", p.Name) prompt := &survey.Confirm{ @@ -43,8 +43,8 @@ func (p *Project) New(ctx context.Context, dir string, layout string, branch str return err } e := os.Rename( - path.Join(to, "cmd", "server"), - path.Join(to, "cmd", p.Name), + filepath.Join(to, "cmd", "server"), + filepath.Join(to, "cmd", p.Name), ) if e != nil { return e diff --git a/cmd/kratos/internal/project/project.go b/cmd/kratos/internal/project/project.go index f1f2cea0c..fffa0fdc1 100644 --- a/cmd/kratos/internal/project/project.go +++ b/cmd/kratos/internal/project/project.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "os" - "path" "path/filepath" "strings" "time" @@ -80,7 +79,7 @@ func run(_ *cobra.Command, args []string) { return } - mod, e := base.ModulePath(path.Join(projectRoot, "go.mod")) + mod, e := base.ModulePath(filepath.Join(projectRoot, "go.mod")) if e != nil { panic(e) } @@ -136,6 +135,6 @@ func getgomodProjectRoot(dir string) string { } func gomodIsNotExistIn(dir string) bool { - _, e := os.Stat(path.Join(dir, "go.mod")) + _, e := os.Stat(filepath.Join(dir, "go.mod")) return os.IsNotExist(e) } diff --git a/cmd/kratos/internal/proto/add/proto.go b/cmd/kratos/internal/proto/add/proto.go index 8c716dc60..88184a28c 100644 --- a/cmd/kratos/internal/proto/add/proto.go +++ b/cmd/kratos/internal/proto/add/proto.go @@ -3,7 +3,7 @@ package add import ( "fmt" "os" - "path" + "path/filepath" ) // Proto is a proto generator. @@ -26,13 +26,13 @@ func (p *Proto) Generate() error { if err != nil { panic(err) } - to := path.Join(wd, p.Path) + to := filepath.Join(wd, p.Path) if _, err := os.Stat(to); os.IsNotExist(err) { if err := os.MkdirAll(to, 0o700); err != nil { return err } } - name := path.Join(to, p.Name) + name := filepath.Join(to, p.Name) if _, err := os.Stat(name); !os.IsNotExist(err) { return fmt.Errorf("%s already exists", p.Name) } diff --git a/cmd/kratos/internal/proto/server/server.go b/cmd/kratos/internal/proto/server/server.go index 41fb9ee74..35e8f90c3 100644 --- a/cmd/kratos/internal/proto/server/server.go +++ b/cmd/kratos/internal/proto/server/server.go @@ -4,7 +4,7 @@ import ( "fmt" "log" "os" - "path" + "path/filepath" "strings" "github.com/emicklei/proto" @@ -76,7 +76,7 @@ func run(_ *cobra.Command, args []string) { return } for _, s := range res { - to := path.Join(targetDir, strings.ToLower(s.Service)+".go") + to := filepath.Join(targetDir, strings.ToLower(s.Service)+".go") if _, err := os.Stat(to); !os.IsNotExist(err) { fmt.Fprintf(os.Stderr, "%s already exists: %s\n", s.Service, to) continue diff --git a/cmd/kratos/internal/run/run.go b/cmd/kratos/internal/run/run.go index 005c832af..2def97a1f 100644 --- a/cmd/kratos/internal/run/run.go +++ b/cmd/kratos/internal/run/run.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "os/exec" - "path" "path/filepath" "strings" @@ -108,7 +107,7 @@ func findCMD(base string) (map[string]string, error) { } for _, fileInfo := range paths { if fileInfo.IsDir() { - abs := path.Join(walkPath, fileInfo.Name()) + abs := filepath.Join(walkPath, fileInfo.Name()) cmdPath[strings.TrimPrefix(abs, wd)] = abs } }