Implement api

This commit is contained in:
d1slike committed 2024-05-08 15:40:14 +03:00
1 parent 80a99c425b
commit b2e34c00a4
30 files changed
+708 -69

No files matched your search

+7 -5
View File
@@ -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
}