-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
111 lines (95 loc) · 2.07 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// TODO: Separate routes out into other fuctions and so on.
package main
import (
"database/sql"
"encoding/json"
"strconv"
"time"
"github.com/lib/pq"
)
type NullInt64 struct{ sql.NullInt64 }
type NullString struct{ sql.NullString }
type NullTime struct{ pq.NullTime }
func (s *NullString) UnmarshalJSON(data []byte) error {
s.Valid = true
s.String = string(data)
return json.Unmarshal(data, &s.String)
}
func (s *NullInt64) UnmarshalJSON(data []byte) error {
s.Valid = true
val, err := strconv.Atoi(string(data))
s.Int64 = int64(val)
return err
}
func (s *NullTime) UnmarshalJSON(data []byte) error {
s.Valid = true
return s.Time.UnmarshalJSON(data)
}
func (s *NullString) Set(o string) {
s.Valid = true
s.String = o
}
func (s *NullInt64) Set(o int64) {
s.Valid = true
s.Int64 = o
}
func (s *NullTime) Set(o time.Time) {
s.Valid = true
s.Time = o
}
func (s NullString) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String)
}
func (s NullInt64) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Int64)
}
func (s NullTime) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Time)
}
type User struct {
Handle NullString
Email NullString
Bio NullString
ImageURL NullString
}
type Comment struct {
ID NullInt64
UserID NullInt64
Content NullString
ParentListingID NullInt64
CreateDate NullTime
EndDate NullTime
}
type DirectMessage struct {
ID NullInt64
UserID NullInt64
Content NullString
ParentListingID NullInt64
CreateDate NullTime
EndDate NullTime
}
type Listing struct {
ListingID NullInt64
UserID NullInt64
Title NullString
Content NullString
Price NullString
Condition NullString
CreateDate NullTime
EndDate NullTime
}
type Book struct {
Id NullInt64
Title NullString
Author NullString
Description NullString
ImageUrl NullString
ISBN_13 NullString
ISBN_10 NullString
}
type Course struct {
Id NullInt64
CreatorID NullInt64
Title NullString
Description NullString
}