-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCache.go
51 lines (43 loc) · 1.04 KB
/
Cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"time"
"crypto/md5"
"encoding/hex"
"encoding/json"
"github.com/patrickmn/go-cache"
)
//--
var authCache = cache.New(5*time.Hour, 5*time.Hour)
var chargeCache = cache.New(5*time.Hour, 5*time.Hour)
var captureCache = cache.New(5*time.Hour, 5*time.Hour)
var voidCache = cache.New(5*time.Hour, 5*time.Hour)
type CacheObject struct {
Status int
RequestId string
RequestHash string
Idempotency string
Charge ChargeObject
Refund RefundData
Error ErrorResponse
Type string
}
func MD5Hash(v interface{}) (string) {
out, err := json.Marshal(v)
if err != nil {
panic(err)
}
aStringToHash := []byte(out)
//Get the hashes in bytes
md5Bytes := md5.Sum(aStringToHash)
//hash
return hex.EncodeToString(md5Bytes[:])
}
//cache to manage idempotency
var idempotencyCache = cache.New(5*time.Hour, 5*time.Hour)
//
type Idempotency struct {
Type string
RequestId string
ChargeId string
RequestHash string
}