1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-13 17:22:27 +08:00

fix: fix lint issue

This commit is contained in:
dudaodong
2022-12-10 16:41:40 +08:00
parent 2725575d2f
commit 13bbe19ab2
17 changed files with 142 additions and 98 deletions

View File

@@ -11,7 +11,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"path"
@@ -78,13 +77,16 @@ func CopyFile(srcFilePath string, dstFilePath string) error {
var tmp = make([]byte, 1024*4)
for {
n, err := srcFile.Read(tmp)
distFile.Write(tmp[:n])
if err != nil {
if err == io.EOF {
return nil
}
return err
}
_, err = distFile.Write(tmp[:n])
if err != nil {
return err
}
}
}
@@ -102,7 +104,7 @@ func ClearFile(path string) error {
//ReadFileToString return string of file content
func ReadFileToString(path string) (string, error) {
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return "", err
}
@@ -141,7 +143,7 @@ func ListFileNames(path string) ([]string, error) {
return []string{}, nil
}
fs, err := ioutil.ReadDir(path)
fs, err := os.ReadDir(path)
if err != nil {
return []string{}, err
}
@@ -172,7 +174,7 @@ func Zip(fpath string, destPath string) error {
archive := zip.NewWriter(zipFile)
defer archive.Close()
filepath.Walk(fpath, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(fpath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
@@ -209,6 +211,10 @@ func Zip(fpath string, destPath string) error {
return nil
})
if err != nil {
return err
}
return nil
}
@@ -229,9 +235,13 @@ func UnZip(zipFile string, destPath string) error {
}
if f.FileInfo().IsDir() {
os.MkdirAll(path, os.ModePerm)
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
return err
}
} else {
if err = os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
err = os.MkdirAll(filepath.Dir(path), os.ModePerm)
if err != nil {
return err
}

View File

@@ -25,9 +25,10 @@ func TestCreateFile(t *testing.T) {
f := "./text.txt"
if CreateFile(f) {
file, err := os.Open(f)
defer file.Close()
assert.IsNil(err)
assert.Equal(f, file.Name())
defer file.Close()
} else {
t.FailNow()
}
@@ -113,7 +114,11 @@ func TestReadFileToString(t *testing.T) {
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
defer f.Close()
f.WriteString("hello world")
_, err := f.WriteString("hello world")
if err != nil {
t.Log(err)
}
content, _ := ReadFileToString(path)
assert.Equal("hello world", content)
@@ -130,9 +135,12 @@ func TestClearFile(t *testing.T) {
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
defer f.Close()
f.WriteString("hello world")
_, err := f.WriteString("hello world")
if err != nil {
t.Log(err)
}
err := ClearFile(path)
err = ClearFile(path)
assert.IsNil(err)
content, _ := ReadFileToString(path)
@@ -148,8 +156,13 @@ func TestReadFileByLine(t *testing.T) {
CreateFile(path)
f, _ := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0777)
defer f.Close()
f.WriteString("hello\nworld")
_, err := f.WriteString("hello\nworld")
if err != nil {
t.Log(err)
}
expected := []string{"hello", "world"}
actual, _ := ReadFileByLine(path)