-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathuser.go
274 lines (236 loc) · 6.07 KB
/
user.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
)
// User is the API representation of a user.
//
// swagger:model User
type User struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
RefreshToken *string `json:"-"`
Token *string `json:"-"`
Favorites *[]string `json:"favorites,omitempty"`
Active *bool `json:"active,omitempty"`
Admin *bool `json:"admin,omitempty"`
Dashboards *[]string `json:"dashboards,omitempty"`
}
// Crop creates a duplicate of the User with certain fields cropped.
//
// Generally used for cropping large fields that aren't useful for all API calls like favorites and dashboards.
func (u *User) Crop() *User {
return &User{
ID: u.ID,
Name: u.Name,
RefreshToken: u.RefreshToken,
Token: u.Token,
Active: u.Active,
}
}
// Environment returns a list of environment variables
// provided from the fields of the User type.
func (u *User) Environment() map[string]string {
return map[string]string{
"VELA_USER_ACTIVE": ToString(u.GetActive()),
"VELA_USER_ADMIN": ToString(u.GetAdmin()),
"VELA_USER_FAVORITES": ToString(u.GetFavorites()),
"VELA_USER_NAME": ToString(u.GetName()),
}
}
// GetID returns the ID field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetID() int64 {
// return zero value if User type or ID field is nil
if u == nil || u.ID == nil {
return 0
}
return *u.ID
}
// GetName returns the Name field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetName() string {
// return zero value if User type or Name field is nil
if u == nil || u.Name == nil {
return ""
}
return *u.Name
}
// GetRefreshToken returns the RefreshToken field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetRefreshToken() string {
// return zero value if User type or RefreshToken field is nil
if u == nil || u.RefreshToken == nil {
return ""
}
return *u.RefreshToken
}
// GetToken returns the Token field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetToken() string {
// return zero value if User type or Token field is nil
if u == nil || u.Token == nil {
return ""
}
return *u.Token
}
// GetActive returns the Active field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetActive() bool {
// return zero value if User type or Active field is nil
if u == nil || u.Active == nil {
return false
}
return *u.Active
}
// GetAdmin returns the Admin field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetAdmin() bool {
// return zero value if User type or Admin field is nil
if u == nil || u.Admin == nil {
return false
}
return *u.Admin
}
// GetFavorites returns the Favorites field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetFavorites() []string {
// return zero value if User type or Favorites field is nil
if u == nil || u.Favorites == nil {
return []string{}
}
return *u.Favorites
}
// GetDashboards returns the Dashboards field.
//
// When the provided User type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (u *User) GetDashboards() []string {
// return zero value if User type or Dashboard field is nil
if u == nil || u.Dashboards == nil {
return []string{}
}
return *u.Dashboards
}
// SetID sets the ID field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetID(v int64) {
// return if User type is nil
if u == nil {
return
}
u.ID = &v
}
// SetName sets the Name field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetName(v string) {
// return if User type is nil
if u == nil {
return
}
u.Name = &v
}
// SetRefreshToken sets the RefreshToken field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetRefreshToken(v string) {
// return if User type is nil
if u == nil {
return
}
u.RefreshToken = &v
}
// SetToken sets the Token field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetToken(v string) {
// return if User type is nil
if u == nil {
return
}
u.Token = &v
}
// SetActive sets the Active field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetActive(v bool) {
// return if User type is nil
if u == nil {
return
}
u.Active = &v
}
// SetAdmin sets the Admin field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetAdmin(v bool) {
// return if User type is nil
if u == nil {
return
}
u.Admin = &v
}
// SetFavorites sets the Favorites field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetFavorites(v []string) {
// return if User type is nil
if u == nil {
return
}
u.Favorites = &v
}
// SetDashboard sets the Dashboard field.
//
// When the provided User type is nil, it
// will set nothing and immediately return.
func (u *User) SetDashboards(v []string) {
// return if User type is nil
if u == nil {
return
}
u.Dashboards = &v
}
// String implements the Stringer interface for the User type.
func (u *User) String() string {
return fmt.Sprintf(`{
Active: %t,
Admin: %t,
Dashboards: %s,
Favorites: %s,
ID: %d,
Name: %s,
Token: %s,
}`,
u.GetActive(),
u.GetAdmin(),
u.GetDashboards(),
u.GetFavorites(),
u.GetID(),
u.GetName(),
u.GetToken(),
)
}