mirror of
https://github.com/tiger1103/gfast.git
synced 2026-10-01 05:07:04 +00:00
系统初始化
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user