🆕为实现数据迁移以及备份新增配置导出
This commit is contained in:
28
utils/file.go
Normal file
28
utils/file.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type fileUtils struct{}
|
||||
|
||||
func FileUtils() fileUtils {
|
||||
return fileUtils{}
|
||||
}
|
||||
|
||||
// GenerateFile
|
||||
// @description: 生成文件
|
||||
// @receiver fileUtils
|
||||
// @param filename 文件名称
|
||||
// @param content 文件内容
|
||||
// @return error
|
||||
func (fileUtils) GenerateFile(filename string, content []byte) (filepath string, err error) {
|
||||
path := "/tmp/"
|
||||
if os.Getenv("GIN_MODE") != "release" {
|
||||
path = "E:\\Workspace\\Go\\wireguard-ui\\template\\tmp\\"
|
||||
}
|
||||
filepath = fmt.Sprintf("%s%s", path, filename)
|
||||
err = os.WriteFile(filepath, content, 0777)
|
||||
return filepath, err
|
||||
}
|
Reference in New Issue
Block a user