1 Star 0 Fork 0

h79 / gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-09-15 20:16 . error
package token
import (
"encoding/gob"
"gitee.com/h79/goutils/common/algorithm"
"gitee.com/h79/goutils/common/logger"
"io"
"mime/multipart"
"os"
"path/filepath"
)
func DefaultForm(w *multipart.Writer, field, filename string) error {
writer, err := w.CreateFormFile(field, filepath.Base(filename))
if err != nil {
return Error(-1, err.Error())
}
fh, err := os.Open(filename)
if err != nil {
return Error(-1, err.Error())
}
defer fh.Close()
_, err = io.Copy(writer, fh)
return err
}
func saveFile(filename string, writer func(en *gob.Encoder) error) error {
file, er := os.Create(filename)
if er != nil {
return er
}
defer file.Close()
encoder := gob.NewEncoder(file)
return writer(encoder)
}
func loadFile(filename string, reader func(de *gob.Decoder) error) error {
file, er := os.Open(filename)
if er != nil {
return er
}
defer file.Close()
de := gob.NewDecoder(file)
return reader(de)
}
func deleteFile(filename string) {
if err := os.Remove(filename); err != nil {
logger.Debug("Token: delete path failure,err= %v", err)
}
}
func checkPath(path string) error {
if len(path) == 0 {
return ErrParam
}
if err := os.MkdirAll(path, os.ModePerm); err != nil {
logger.Error("Token: mkdir the alias path failure, err= %v", err)
return err
}
return nil
}
func fileId(id string) string {
return algorithm.Md5String(id)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.106

搜索帮助

Bbcd6f05 5694891 0cc6727d 5694891