File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 4
4
"context"
5
5
"crypto/md5"
6
6
"encoding/base64"
7
+ "hash/fnv"
7
8
"net/url"
8
9
"strconv"
9
10
"time"
@@ -54,8 +55,9 @@ func (c *extCache) Generate(urlStr string) (string, error) {
54
55
return "" , err
55
56
}
56
57
57
- expireStr := strconv .FormatInt (time .Now ().Unix ()+ int64 (c .cfg .Expires ), 10 )
58
58
uri := "/" + u .Scheme + "/" + u .Host + u .Path
59
+ expire := snapExpire (uri , time .Now ().Unix (), int64 (c .cfg .Expires ))
60
+ expireStr := strconv .FormatInt (expire , 10 )
59
61
h := md5 .Sum ([]byte (expireStr + c .cfg .HashPrefix + uri + c .cfg .Secret ))
60
62
sig := base64 .RawURLEncoding .EncodeToString (h [:])
61
63
@@ -65,3 +67,10 @@ func (c *extCache) Generate(urlStr string) (string, error) {
65
67
66
68
return c .cfg .Prefix + uri + "?" + q .Encode (), nil
67
69
}
70
+
71
+ func snapExpire (key string , now , min int64 ) int64 {
72
+ h := fnv .New32 ()
73
+ _ , _ = h .Write ([]byte (key ))
74
+ expire := (now + min + 0xFFFF )&^0xFFFF + int64 (h .Sum32 ()& 0xFFFF )
75
+ return expire
76
+ }
You can’t perform that action at this time.
0 commit comments