-
Notifications
You must be signed in to change notification settings - Fork 1
/
cookie.go
59 lines (51 loc) · 1.26 KB
/
cookie.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
52
53
54
55
56
57
58
59
package ytuploader
import (
"encoding/json"
"net/http"
"os"
"time"
)
type Cookie struct {
Domain string `json:"domain"`
ExpirationDate float64 `json:"expirationDate"`
HostOnly bool `json:"hostOnly"`
HTTPOnly bool `json:"httpOnly"`
Name string `json:"name"`
Path string `json:"path"`
SameSite string `json:"sameSite"`
Secure bool `json:"secure"`
Session bool `json:"session"`
StoreID string `json:"storeId"`
Value string `json:"value"`
ID int `json:"id"`
}
func (c *Cookie) Builtin() *http.Cookie {
return &http.Cookie{
Name: c.Name,
Domain: c.Domain,
Value: c.Value,
Path: c.Path,
SameSite: http.SameSiteNoneMode,
Expires: time.Unix(int64(c.ExpirationDate), 0),
Secure: c.Secure,
}
}
func ParseCookiesFromJSONFile(path string) (Cookies, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
var cookies []*Cookie
if err := json.NewDecoder(file).Decode(&cookies); err != nil {
return nil, err
}
return cookies, nil
}
type Cookies []*Cookie
func (cookies Cookies) Builtin() []*http.Cookie {
c := []*http.Cookie{}
for _, cookie := range cookies {
c = append(c, cookie.Builtin())
}
return c
}