-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes.go
executable file
·57 lines (42 loc) · 1.05 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Code generated by `gogenitor`. DO NOT EDIT.
package sumup
import (
"encoding/json"
"time"
)
type Date struct{ time.Time }
func (d Date) String() string {
return d.Format(time.DateOnly)
}
const jsonDateFormat = `"` + time.DateOnly + `"`
var _ json.Unmarshaler = (*Date)(nil)
func (d *Date) UnmarshalJSON(b []byte) (err error) {
date, err := time.Parse(jsonDateFormat, string(b))
if err != nil {
return err
}
d.Time = date
return
}
var _ json.Marshaler = (*Date)(nil)
func (d Date) MarshalJSON() ([]byte, error) {
return []byte(d.Time.Format(jsonDateFormat)), nil
}
type Time struct{ time.Time }
func (t Time) String() string {
return t.Format(time.TimeOnly)
}
const jsonTimeFormat = `"` + time.TimeOnly + `"`
var _ json.Unmarshaler = (*Time)(nil)
func (t *Time) UnmarshalJSON(b []byte) (err error) {
date, err := time.Parse(jsonTimeFormat, string(b))
if err != nil {
return err
}
t.Time = date
return
}
var _ json.Marshaler = (*Time)(nil)
func (t Time) MarshalJSON() ([]byte, error) {
return []byte(t.Time.Format(jsonTimeFormat)), nil
}