mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-12 02:28:05 +02:00
fix: package path to filepath (#2672)
* fix: package path to filepath * fix: automatic import * fix: automatic import
This commit is contained in:
parent
f47a238478
commit
99ccd00434
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user