1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-16 07:18:37 +00:00

Upgrade xorm to v1.1.0 (#15869)

This commit is contained in:
Lunny Xiao
2021-05-15 03:17:06 +08:00
committed by GitHub
parent e2f39c2b64
commit f6be429781
55 changed files with 1309 additions and 438 deletions

View File

@@ -13,22 +13,26 @@ import (
"io"
)
// md5 hash string
// Md5 return md5 hash string
func Md5(str string) string {
m := md5.New()
io.WriteString(m, str)
return fmt.Sprintf("%x", m.Sum(nil))
}
// Encode Encode data
func Encode(data interface{}) ([]byte, error) {
//return JsonEncode(data)
return GobEncode(data)
}
// Decode decode data
func Decode(data []byte, to interface{}) error {
//return JsonDecode(data, to)
return GobDecode(data, to)
}
// GobEncode encode data with gob
func GobEncode(data interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
@@ -39,12 +43,14 @@ func GobEncode(data interface{}) ([]byte, error) {
return buf.Bytes(), nil
}
// GobDecode decode data with gob
func GobDecode(data []byte, to interface{}) error {
buf := bytes.NewBuffer(data)
dec := gob.NewDecoder(buf)
return dec.Decode(to)
}
// JsonEncode encode data with json
func JsonEncode(data interface{}) ([]byte, error) {
val, err := json.Marshal(data)
if err != nil {
@@ -53,6 +59,7 @@ func JsonEncode(data interface{}) ([]byte, error) {
return val, nil
}
// JsonDecode decode data with json
func JsonDecode(data []byte, to interface{}) error {
return json.Unmarshal(data, to)
}