-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance_v1.go
376 lines (293 loc) · 9.62 KB
/
instance_v1.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// InstanceV1 InstanceV1 models information about this instance.
//
// swagger:model InstanceV1
type InstanceV1 struct {
// The domain of accounts on this instance.
// This will not necessarily be the same as
// simply the Host part of the URI.
// Example: example.org
AccountDomain string `json:"account_domain,omitempty"`
// New account registrations require admin approval.
ApprovalRequired bool `json:"approval_required,omitempty"`
// Custom CSS for the instance.
CustomCSS string `json:"custom_css,omitempty"`
// Whether or not instance is running in DEBUG mode. Omitted if false.
Debug bool `json:"debug,omitempty"`
// Description of the instance.
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the 'about' page for an instance.
Description string `json:"description,omitempty"`
// Raw (unparsed) version of description.
DescriptionText string `json:"description_text,omitempty"`
// An email address that may be used for inquiries.
// Example: [email protected]
Email string `json:"email,omitempty"`
// Invites are enabled on this instance.
InvitesEnabled bool `json:"invites_enabled,omitempty"`
// Primary language of the instance.
// Example: ["en"]
Languages []string `json:"languages"`
// Maximum allowed length of a post on this instance, in characters.
//
// This is provided for compatibility with Tusky and other apps.
// Example: 5000
MaxTootChars uint64 `json:"max_toot_chars,omitempty"`
// New account registrations are enabled on this instance.
Registrations bool `json:"registrations,omitempty"`
// An itemized list of rules for this instance.
Rules []*InstanceRule `json:"rules"`
// A shorter description of the instance.
//
// Should be HTML formatted, but might be plaintext.
//
// This should be displayed on the instance splash/landing page.
ShortDescription string `json:"short_description,omitempty"`
// Raw (unparsed) version of short description.
ShortDescriptionText string `json:"short_description_text,omitempty"`
// Statistics about the instance: number of posts, accounts, etc.
// Values are pointers because we don't want to skip 0 values when
// rendering stats via web templates.
Stats map[string]int64 `json:"stats,omitempty"`
// Terms and conditions for accounts on this instance.
Terms string `json:"terms,omitempty"`
// Raw (unparsed) version of terms.
TermsRaw string `json:"terms_text,omitempty"`
// URL of the instance avatar/banner image.
// Example: https://example.org/files/instance/thumbnail.jpeg
Thumbnail string `json:"thumbnail,omitempty"`
// Description of the instance thumbnail.
// Example: picture of a cute lil' friendly sloth
ThumbnailDescription string `json:"thumbnail_description,omitempty"`
// URL of the static instance avatar/banner image.
// Example: https://example.org/files/instance/static/thumbnail.webp
ThumbnailStatic string `json:"thumbnail_static,omitempty"`
// MIME type of the static instance thumbnail.
// Example: image/webp
ThumbnailStaticType string `json:"thumbnail_static_type,omitempty"`
// MIME type of the instance thumbnail.
// Example: image/png
ThumbnailType string `json:"thumbnail_type,omitempty"`
// The title of the instance.
// Example: GoToSocial Example Instance
Title string `json:"title,omitempty"`
// The URI of the instance.
// Example: https://gts.example.org
URI string `json:"uri,omitempty"`
// The version of GoToSocial installed on the instance.
//
// This will contain at least a semantic version number.
//
// It may also contain, after a space, the short git commit ID of the running software.
// Example: 0.1.1 cb85f65
Version string `json:"version,omitempty"`
// configuration
Configuration *InstanceV1Configuration `json:"configuration,omitempty"`
// contact account
ContactAccount *Account `json:"contact_account,omitempty"`
// urls
Urls *InstanceV1URLs `json:"urls,omitempty"`
}
// Validate validates this instance v1
func (m *InstanceV1) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateRules(formats); err != nil {
res = append(res, err)
}
if err := m.validateConfiguration(formats); err != nil {
res = append(res, err)
}
if err := m.validateContactAccount(formats); err != nil {
res = append(res, err)
}
if err := m.validateUrls(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *InstanceV1) validateRules(formats strfmt.Registry) error {
if swag.IsZero(m.Rules) { // not required
return nil
}
for i := 0; i < len(m.Rules); i++ {
if swag.IsZero(m.Rules[i]) { // not required
continue
}
if m.Rules[i] != nil {
if err := m.Rules[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("rules" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("rules" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *InstanceV1) validateConfiguration(formats strfmt.Registry) error {
if swag.IsZero(m.Configuration) { // not required
return nil
}
if m.Configuration != nil {
if err := m.Configuration.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("configuration")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("configuration")
}
return err
}
}
return nil
}
func (m *InstanceV1) validateContactAccount(formats strfmt.Registry) error {
if swag.IsZero(m.ContactAccount) { // not required
return nil
}
if m.ContactAccount != nil {
if err := m.ContactAccount.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("contact_account")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("contact_account")
}
return err
}
}
return nil
}
func (m *InstanceV1) validateUrls(formats strfmt.Registry) error {
if swag.IsZero(m.Urls) { // not required
return nil
}
if m.Urls != nil {
if err := m.Urls.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("urls")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("urls")
}
return err
}
}
return nil
}
// ContextValidate validate this instance v1 based on the context it is used
func (m *InstanceV1) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateRules(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateConfiguration(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateContactAccount(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateUrls(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *InstanceV1) contextValidateRules(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.Rules); i++ {
if m.Rules[i] != nil {
if swag.IsZero(m.Rules[i]) { // not required
return nil
}
if err := m.Rules[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("rules" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("rules" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *InstanceV1) contextValidateConfiguration(ctx context.Context, formats strfmt.Registry) error {
if m.Configuration != nil {
if swag.IsZero(m.Configuration) { // not required
return nil
}
if err := m.Configuration.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("configuration")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("configuration")
}
return err
}
}
return nil
}
func (m *InstanceV1) contextValidateContactAccount(ctx context.Context, formats strfmt.Registry) error {
if m.ContactAccount != nil {
if swag.IsZero(m.ContactAccount) { // not required
return nil
}
if err := m.ContactAccount.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("contact_account")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("contact_account")
}
return err
}
}
return nil
}
func (m *InstanceV1) contextValidateUrls(ctx context.Context, formats strfmt.Registry) error {
if m.Urls != nil {
if swag.IsZero(m.Urls) { // not required
return nil
}
if err := m.Urls.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("urls")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("urls")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *InstanceV1) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *InstanceV1) UnmarshalBinary(b []byte) error {
var res InstanceV1
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}