Implement api
This commit is contained in:
1 parent
80a99c425b
commit
b2e34c00a4
30 files changed
+708
-69
No files matched your search
@@ -1,8 +1,6 @@
|
||||
package xtypes
|
||||
|
||||
type Bool struct {
|
||||
Value bool
|
||||
}
|
||||
type Bool bool
|
||||
|
||||
func (l Bool) MarshalJSON() ([]byte, error) {
|
||||
return l.MarshalText()
|
||||
@@ -13,13 +11,13 @@ func (l *Bool) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
func (l Bool) MarshalText() ([]byte, error) {
|
||||
if l.Value {
|
||||
if l {
|
||||
return []byte("1"), nil
|
||||
}
|
||||
return []byte("0"), nil
|
||||
}
|
||||
|
||||
func (l *Bool) UnmarshalText(data []byte) error {
|
||||
l.Value = string(data) == "1"
|
||||
*l = string(data) == "1"
|
||||
return nil
|
||||
}
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Time struct {
|
||||
Value time.Time
|
||||
}
|
||||
type Time time.Time
|
||||
|
||||
func (l Time) MarshalJSON() ([]byte, error) {
|
||||
return l.MarshalText()
|
||||
@@ -18,15 +16,19 @@ func (l *Time) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
func (l Time) MarshalText() ([]byte, error) {
|
||||
value := strconv.Itoa(int(l.Value.Unix()))
|
||||
t := time.Time(l)
|
||||
value := strconv.Itoa(int(t.Unix()))
|
||||
return []byte(value), nil
|
||||
}
|
||||
|
||||
func (l *Time) UnmarshalText(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
value, err := strconv.Atoi(string(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
l.Value = time.Unix(int64(value), 0)
|
||||
*l = Time(time.Unix(int64(value), 0))
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user