🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
This commit is contained in:
commit
6981148727
107 files changed
+12463
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Bytes2DataURI 将字节转换为 Data URI
|
||||
func Bytes2DataURI(dataBytes []byte, mimeType string) string {
|
||||
encoded := base64.StdEncoding.EncodeToString(dataBytes)
|
||||
return fmt.Sprintf("data:%s;base64,%s", mimeType, encoded)
|
||||
}
|
||||
|
||||
// CreateMD5 创建MD5哈希
|
||||
func CreateMD5(s interface{}) string {
|
||||
var data []byte
|
||||
switch v := s.(type) {
|
||||
case string:
|
||||
data = []byte(v)
|
||||
case []byte:
|
||||
data = v
|
||||
default:
|
||||
data = []byte(fmt.Sprintf("%v", v))
|
||||
}
|
||||
|
||||
hasher := md5.New()
|
||||
hasher.Write(data)
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user