pcm-openi/common/util.go

34 lines
656 B
Go

package common
import (
"crypto/md5"
"encoding/hex"
"github.com/go-resty/resty/v2"
"io"
"mime/multipart"
"strconv"
"time"
)
func GetRestyRequest(timeoutSeconds int64) *resty.Request {
client := resty.New().SetTimeout(time.Duration(timeoutSeconds) * time.Second)
request := client.R()
return request
}
func GetFileMd5(file multipart.File) (string, error) {
hash := md5.New()
if _, err := io.Copy(hash, file); err != nil {
return "", err
}
// 计算MD5并转换为16进制字符串
md5Bytes := hash.Sum(nil)
md5Str := hex.EncodeToString(md5Bytes)
return md5Str, nil
}
func Bool2String(b bool) string {
return strconv.FormatBool(b)
}