-
Notifications
You must be signed in to change notification settings - Fork 2
/
cookie.go
37 lines (32 loc) · 935 Bytes
/
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
package request
import (
"encoding/json"
"net/http"
"github.com/gildas/go-core"
"github.com/gildas/go-errors"
)
type cookie http.Cookie
func (c cookie) MarshalJSON() ([]byte, error) {
data, err := json.Marshal(struct {
Name string `json:"name"`
Value string `json:"value"`
Path string `json:"path,omitempty"`
Domain string `json:"domain,omitempty"`
Expires core.Time `json:"expires,omitempty"`
MaxAge int `json:"maxAge,omitempty"`
Secure bool `json:"secure,omitempty"`
HttpOnly bool `json:"httpOnly,omitempty"`
SameSite http.SameSite `json:"sameSite,omitempty"`
}{
Name: c.Name,
Value: c.Value,
Path: c.Path,
Domain: c.Domain,
Expires: core.Time(c.Expires),
MaxAge: c.MaxAge,
Secure: c.Secure,
HttpOnly: c.HttpOnly,
SameSite: c.SameSite,
})
return data, errors.JSONMarshalError.Wrap(err)
}