aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/caches/encode.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-03-22 23:12:55 +0800
committerGitHub <noreply@github.com>2020-03-22 11:12:55 -0400
commitc61b902538e8e4b2bb83136f190e044a6bbcdd9b (patch)
treebc08142f5ced69721ab14793b8dc62aa83314268 /vendor/xorm.io/xorm/caches/encode.go
parentdcaa5643d70cd1be72e53e82a30d2bc6e5f8de92 (diff)
downloadgitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.tar.gz
gitea-c61b902538e8e4b2bb83136f190e044a6bbcdd9b.zip
Upgrade xorm to v1.0.0 (#10646)
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
Diffstat (limited to 'vendor/xorm.io/xorm/caches/encode.go')
-rw-r--r--vendor/xorm.io/xorm/caches/encode.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/xorm.io/xorm/caches/encode.go b/vendor/xorm.io/xorm/caches/encode.go
new file mode 100644
index 0000000000..4ba39924a5
--- /dev/null
+++ b/vendor/xorm.io/xorm/caches/encode.go
@@ -0,0 +1,58 @@
+// Copyright 2020 The Xorm Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package caches
+
+import (
+ "bytes"
+ "crypto/md5"
+ "encoding/gob"
+ "encoding/json"
+ "fmt"
+ "io"
+)
+
+// md5 hash string
+func Md5(str string) string {
+ m := md5.New()
+ io.WriteString(m, str)
+ return fmt.Sprintf("%x", m.Sum(nil))
+}
+func Encode(data interface{}) ([]byte, error) {
+ //return JsonEncode(data)
+ return GobEncode(data)
+}
+
+func Decode(data []byte, to interface{}) error {
+ //return JsonDecode(data, to)
+ return GobDecode(data, to)
+}
+
+func GobEncode(data interface{}) ([]byte, error) {
+ var buf bytes.Buffer
+ enc := gob.NewEncoder(&buf)
+ err := enc.Encode(&data)
+ if err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil
+}
+
+func GobDecode(data []byte, to interface{}) error {
+ buf := bytes.NewBuffer(data)
+ dec := gob.NewDecoder(buf)
+ return dec.Decode(to)
+}
+
+func JsonEncode(data interface{}) ([]byte, error) {
+ val, err := json.Marshal(data)
+ if err != nil {
+ return nil, err
+ }
+ return val, nil
+}
+
+func JsonDecode(data []byte, to interface{}) error {
+ return json.Unmarshal(data, to)
+}