From 5b33dd59d9ecf48ed1410bb72e64278c66521de2 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 20 Feb 2021 15:07:49 +0800 Subject: [PATCH] fix golint issues in core/jsontype (#489) --- core/jsontype/time.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/jsontype/time.go b/core/jsontype/time.go index 8d38c6d7..ac8be8be 100644 --- a/core/jsontype/time.go +++ b/core/jsontype/time.go @@ -7,14 +7,17 @@ import ( "github.com/globalsign/mgo/bson" ) +// MilliTime represents time.Time that works better with mongodb. type MilliTime struct { time.Time } +// MarshalJSON marshals mt to json bytes. func (mt MilliTime) MarshalJSON() ([]byte, error) { return json.Marshal(mt.Milli()) } +// UnmarshalJSON unmarshals data into mt. func (mt *MilliTime) UnmarshalJSON(data []byte) error { var milli int64 if err := json.Unmarshal(data, &milli); err != nil { @@ -25,14 +28,17 @@ func (mt *MilliTime) UnmarshalJSON(data []byte) error { return nil } +// GetBSON returns BSON base on mt. func (mt MilliTime) GetBSON() (interface{}, error) { return mt.Time, nil } +// SetBSON sets raw into mt. func (mt *MilliTime) SetBSON(raw bson.Raw) error { return raw.Unmarshal(&mt.Time) } +// Milli returns milliseconds for mt. func (mt MilliTime) Milli() int64 { return mt.UnixNano() / int64(time.Millisecond) }