系统初始化

This commit is contained in:
wilgx0
2022-04-22 17:18:40 +08:00
parent 6b1a05ae42
commit 6afe7740d9
10 changed files with 1002 additions and 3 deletions
+32
View File
@@ -17,6 +17,9 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"net"
"os"
"path"
"strings"
)
// EncryptPassword 密码加密
@@ -92,3 +95,32 @@ func GetCityByIp(ip string) string {
return ""
}
}
// 写入文件
func WriteToFile(fileName string, content string) error {
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
return err
}
n, _ := f.Seek(0, os.SEEK_END)
_, err = f.WriteAt([]byte(content), n)
defer f.Close()
return err
}
// 文件或文件夹是否存在
func FileIsExisted(filename string) bool {
existed := true
if _, err := os.Stat(filename); os.IsNotExist(err) {
existed = false
}
return existed
}
// 解析路径获取文件名称及后缀
func ParseFilePath(pathStr string) (fileName string, fileType string) {
fileNameWithSuffix := path.Base(pathStr)
fileType = path.Ext(fileNameWithSuffix)
fileName = strings.TrimSuffix(fileNameWithSuffix, fileType)
return
}