Skip to content

Commit 99e1e22

Browse files
committed
omit zero-time expires and creation fields from JSON output
1 parent 02587c3 commit 99e1e22

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

kooky.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *Cookie) MarshalJSON() ([]byte, error) {
5555
Quoted bool `json:"quoted"`
5656
Path string `json:"path"`
5757
Domain string `json:"domain"`
58-
Expires jsonTime `json:"expires"`
58+
Expires *jsonTime `json:"expires,omitempty"`
5959
RawExpires string `json:"raw_expires,omitempty"`
6060
MaxAge int `json:"max_age"`
6161
Secure bool `json:"secure"`
@@ -65,7 +65,7 @@ func (c *Cookie) MarshalJSON() ([]byte, error) {
6565
Raw string `json:"raw,omitempty"`
6666
Unparsed []string `json:"unparsed,omitempty"`
6767
// extra fields
68-
Creation jsonTime `json:"creation"`
68+
Creation *jsonTime `json:"creation,omitempty"`
6969
Browser string `json:"browser,omitempty"`
7070
Profile string `json:"profile,omitempty"`
7171
IsDefaultProfile bool `json:"is_default_profile"`
@@ -77,7 +77,6 @@ func (c *Cookie) MarshalJSON() ([]byte, error) {
7777
Quoted: c.Cookie.Quoted,
7878
Path: c.Cookie.Path,
7979
Domain: c.Cookie.Domain,
80-
Expires: jsonTime{c.Cookie.Expires},
8180
RawExpires: c.Cookie.RawExpires,
8281
MaxAge: c.Cookie.MaxAge,
8382
Secure: c.Cookie.Secure,
@@ -86,9 +85,14 @@ func (c *Cookie) MarshalJSON() ([]byte, error) {
8685
Partitioned: c.Cookie.Partitioned,
8786
Raw: c.Cookie.Raw,
8887
Unparsed: c.Cookie.Unparsed,
89-
Creation: jsonTime{c.Creation},
9088
Container: c.Container,
9189
}
90+
if !c.Cookie.Expires.IsZero() {
91+
c2.Expires = &jsonTime{c.Cookie.Expires}
92+
}
93+
if !c.Creation.IsZero() {
94+
c2.Creation = &jsonTime{c.Creation}
95+
}
9296
if c.Browser != nil {
9397
c2.Browser = c.Browser.Browser()
9498
c2.Profile = c.Browser.Profile()

0 commit comments

Comments
 (0)