40 lines
790 B
Go
40 lines
790 B
Go
package global
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"git.hpds.cc/Component/logging"
|
|
"go.uber.org/zap"
|
|
"hpds_annotation/config"
|
|
"io"
|
|
"os"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
FileLabelList map[string]bool
|
|
Cfg *config.WebConfig
|
|
Logger *logging.Logger
|
|
maxGoroutinueNum = 5
|
|
GoroutinueChan = make(chan bool, maxGoroutinueNum)
|
|
//encoderPool *sync.Pool
|
|
)
|
|
|
|
func FileMD5(filePath string) (string, error) {
|
|
file, err := os.Open(filePath)
|
|
if err != nil {
|
|
Logger.With(
|
|
zap.String("获取文件MD5错误", filePath),
|
|
).Error(err.Error())
|
|
return "", err
|
|
}
|
|
hash := md5.New()
|
|
_, _ = io.Copy(hash, file)
|
|
return hex.EncodeToString(hash.Sum(nil)), nil
|
|
}
|
|
func deepCopy(s string) string {
|
|
b := make([]byte, len(s))
|
|
copy(b, s)
|
|
return *(*string)(unsafe.Pointer(&b))
|
|
}
|