forked from telanflow/cookiejar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
50 lines (40 loc) · 980 Bytes
/
storage.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
package cookiejar
import (
"net/http"
"crypto/sha1"
"encoding/hex"
redis "github.com/go-redis/redis/v8"
)
type Storage interface {
Set(string, map[string]entry)
Get(string) map[string]entry
Delete(string)
}
func NewFileJar(filename string, o *Options) (http.CookieJar, error) {
store := &FileDrive{
filename: filename,
entries: make(map[string]map[string]entry),
}
store.readEntries()
return New(store, o)
}
func NewEntriesJar(o *Options) (http.CookieJar, error) {
store := &EntriesDrive{
entries: make(map[string]map[string]entry),
}
return New(store, o)
}
func NewRedisJar(namespaces string, client *redis.Client, o *Options) (http.CookieJar, error) {
if namespaces == "" {
namespaces = "cookiejar"
}
r := sha1.Sum([]byte(namespaces))
namespaces = hex.EncodeToString(r[:])
store := &RedisDrive{
client: client,
namespaces: namespaces,
entries: make(map[string]map[string]entry),
}
store.readEntries()
return New(store, o)
}