Browse Source

删除不再使用的工具函数文件

移除了`hash.go`, `http.go`, `restart.go`, `slice.go`, `time.go`, 和 `utf8.go` 文件,因为这些工具函数已不再被项目使用。同时,从`string.go`中移除了与SQL相关的函数,并修正了`path.go`中的拼写错误。
SongZihuan 3 tháng trước cách đây
mục cha
commit
b600128fa6
9 tập tin đã thay đổi với 1 bổ sung180 xóa
  1. 0 8
      src/utils/file.go
  2. 0 10
      src/utils/hash.go
  3. 0 26
      src/utils/http.go
  4. 1 1
      src/utils/path.go
  5. 0 37
      src/utils/restart.go
  6. 0 14
      src/utils/slice.go
  7. 0 8
      src/utils/string.go
  8. 0 26
      src/utils/time.go
  9. 0 50
      src/utils/utf8.go

+ 0 - 8
src/utils/file.go

@@ -30,11 +30,3 @@ func IsFile(path string) bool {
 
 	return !s.IsDir()
 }
-
-func MakeDir(path string) error {
-	if IsExists(path) && IsDir(path) {
-		return nil
-	}
-
-	return os.MkdirAll(path, os.ModePerm)
-}

+ 0 - 10
src/utils/hash.go

@@ -1,10 +0,0 @@
-package utils
-
-import (
-	"crypto/sha256"
-	"fmt"
-)
-
-func SHA256(data []byte) string {
-	return fmt.Sprintf("%x", sha256.Sum256(data))
-}

+ 0 - 26
src/utils/http.go

@@ -1,26 +0,0 @@
-package utils
-
-import (
-	"net/http"
-)
-
-var statusOK = []int{
-	http.StatusOK,
-	http.StatusCreated,
-	http.StatusAccepted,
-	http.StatusNonAuthoritativeInfo,
-	http.StatusNoContent,
-	http.StatusResetContent,
-	http.StatusPartialContent,
-	http.StatusMultiStatus,
-	http.StatusAlreadyReported,
-}
-
-func HttpStatusOK(status int) bool {
-	for _, s := range statusOK {
-		if status == s {
-			return true
-		}
-	}
-	return false
-}

+ 1 - 1
src/utils/path.go

@@ -50,7 +50,7 @@ func CheckIfSubPath(parentPath, childPath string) bool {
 	return strings.HasPrefix(childPath, parentPath)
 }
 
-func CheckIfSubPathNotEqaule(parentPath, childPath string) bool {
+func CheckIfSubPathNotEqual(parentPath, childPath string) bool {
 	parentPath, err := CleanFilePathAbs(parentPath)
 	if err != nil {
 		return false

+ 0 - 37
src/utils/restart.go

@@ -1,37 +0,0 @@
-package utils
-
-import (
-	"os"
-)
-
-func Restart(newArgs ...string) (*os.Process, error) {
-	args := make([]string, 0, len(os.Args))
-	copy(args, os.Args)
-
-	if len(newArgs) != 0 {
-		args = append(args, newArgs...)
-	}
-
-	wd, err := os.Getwd()
-	if err != nil {
-		return nil, err
-	}
-
-	args0, err := os.Executable()
-	if err != nil {
-		return nil, err
-	}
-
-	attr := &os.ProcAttr{
-		Dir:   wd,                                         // 新进程的工作目录
-		Env:   os.Environ(),                               // 新进程的环境变量列表
-		Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, // 对应标准输入,标准输出和标准错误输出,若为nil,表示该进程启动时file是关闭的
-	}
-
-	p, err := os.StartProcess(args0, args[1:], attr)
-	if err != nil {
-		return nil, err
-	}
-
-	return p, nil
-}

+ 0 - 14
src/utils/slice.go

@@ -1,14 +0,0 @@
-package utils
-
-func Filter[E any](src []E, callback func(E) bool) []E {
-	res := make([]E, 0, len(src))
-
-	for i := 0; i < len(src); i++ {
-		srci := src[i]
-		if callback(srci) {
-			res = append(res, srci)
-		}
-	}
-
-	return res
-}

+ 0 - 8
src/utils/string.go

@@ -1,7 +1,6 @@
 package utils
 
 import (
-	"database/sql"
 	"regexp"
 	"strings"
 	"unicode"
@@ -32,13 +31,6 @@ func IsValidEmail(email string) bool {
 	return matched
 }
 
-func GetSQLNullString(s sql.NullString) string {
-	if s.Valid {
-		return s.String
-	}
-	return ""
-}
-
 const NormalConsoleWidth = 80
 
 func FormatTextToWidth(text string, width int) string {

+ 0 - 26
src/utils/time.go

@@ -1,26 +0,0 @@
-package utils
-
-import (
-	"database/sql"
-	"time"
-)
-
-func GetSQLNullTimeUnix(s sql.NullTime) int64 {
-	if s.Valid {
-		return s.Time.Unix()
-	}
-	return 0
-}
-
-func SqlTimeNow() sql.NullTime {
-	return sql.NullTime{
-		Valid: true,
-		Time:  time.Now(),
-	}
-}
-
-func SqlTimeNull() sql.NullTime {
-	return sql.NullTime{
-		Valid: false,
-	}
-}

+ 0 - 50
src/utils/utf8.go

@@ -1,50 +0,0 @@
-package utils
-
-import (
-	"fmt"
-	"unicode"
-	"unicode/utf8"
-)
-
-func IsUTF8(b []byte) bool {
-	return utf8.Valid(b)
-}
-
-func IsUTF8String(s string) bool {
-	return utf8.ValidString(s)
-}
-
-func HasUTF8BOM(data []byte) bool {
-	if len(data) >= 3 && data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF {
-		return true
-	}
-	return false
-}
-
-func RemoveBOMIfExists(data []byte) []byte {
-	if HasUTF8BOM(data) {
-		return data[3:]
-	}
-	return data
-}
-
-func HasInvisibleByteSlice(data []byte) bool {
-	for i := 0; i < len(data); {
-		runeValue, size := utf8.DecodeRune(data[i:])
-		if !unicode.IsPrint(runeValue) {
-			return true
-		}
-		i += size
-	}
-	return false
-}
-
-func HasInvisibleString(str string) bool {
-	for _, runeValue := range str {
-		if !unicode.IsPrint(runeValue) {
-			fmt.Printf("%d\n", runeValue)
-			return true
-		}
-	}
-	return false
-}