add marshal yaml for ts
This commit is contained in:
10
pttodo/ts.go
10
pttodo/ts.go
@@ -8,10 +8,18 @@ import (
|
|||||||
type TS int64
|
type TS int64
|
||||||
|
|
||||||
func (ts TS) MarshalJSON() ([]byte, error) {
|
func (ts TS) MarshalJSON() ([]byte, error) {
|
||||||
|
v, err := ts.MarshalYAML()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return json.Marshal(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ts TS) MarshalYAML() (interface{}, error) {
|
||||||
if ts == 0 {
|
if ts == 0 {
|
||||||
ts = TS(time.Now().Unix())
|
ts = TS(time.Now().Unix())
|
||||||
}
|
}
|
||||||
return json.Marshal(int64(ts))
|
return int64(ts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TS) UnmarshalJSON(b []byte) error {
|
func (ts *TS) UnmarshalJSON(b []byte) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user