package client12import (3"net/http"4"strconv"5"strings"6"time"7)89// Time wraps time.Time overriddin the json marshal/unmarshal to pass10// timestamp as integer11type Time struct {12time.Time13}1415type data struct {16Time Time `json:"time"`17}1819// A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an20// HTTP response or the Cookie header of an HTTP request.21//22// See https://tools.ietf.org/html/rfc6265 for details.23//Stolen from Net/http/cookies24type Cookie struct {25Name string `json:"name"`26Value string `json:"value"`2728Path string `json:"path"` // optional29Domain string `json:"domain"` // optional30Expires time.Time31JSONExpires Time `json:"expires"` // optional32RawExpires string `json:"rawExpires"` // for reading cookies only3334// MaxAge=0 means no 'Max-Age' attribute specified.35// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'36// MaxAge>0 means Max-Age attribute present and given in seconds37MaxAge int `json:"maxAge"`38Secure bool `json:"secure"`39HTTPOnly bool `json:"httpOnly"`40SameSite http.SameSite `json:"sameSite"`41Raw string42Unparsed []string `json:"unparsed"` // Raw text of unparsed attribute-value pairs43}4445// UnmarshalJSON implements json.Unmarshaler inferface.46func (t *Time) UnmarshalJSON(buf []byte) error {47// Try to parse the timestamp integer48ts, err := strconv.ParseInt(string(buf), 10, 64)49if err == nil {50if len(buf) == 19 {51t.Time = time.Unix(ts/1e9, ts%1e9)52} else {53t.Time = time.Unix(ts, 0)54}55return nil56}57str := strings.Trim(string(buf), `"`)58if str == "null" || str == "" {59return nil60}61// Try to manually parse the data62tt, err := ParseDateString(str)63if err != nil {64return err65}66t.Time = tt67return nil68}6970// ParseDateString takes a string and passes it through Approxidate71// Parses into a time.Time72func ParseDateString(dt string) (time.Time, error) {73const layout = "Mon, 02-Jan-2006 15:04:05 MST"7475return time.Parse(layout, dt)76}777879