forked from go-fed/activity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_link.go
586 lines (459 loc) · 16 KB
/
gen_link.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//
package streams
import (
"github.com/go-fed/activity/vocab"
"net/url"
)
// A Link is an indirect, qualified reference to a resource identified by a URL. The fundamental model for links is established by [ RFC5988]. Many of the properties defined by the Activity Vocabulary allow values that are either instances of Object or Link. When a Link is used, it establishes a qualified relation connecting the subject (the containing object) to the resource identified by the href. Properties of the Link are properties of the reference as opposed to properties of the resource. This is a convenience wrapper of a type with the same name in the vocab package. Accessing it with the Raw function allows direct manipulaton of the object, and does not provide the same integrity guarantees as this package.
type Link struct {
// The raw type from the vocab package
raw *vocab.Link
}
// Raw returns the vocab type for manaual manipulation. Note that manipulating the underlying type to be in an inconsistent state may cause this convenience type's methods to later fail.
func (t *Link) Raw() (n *vocab.Link) {
return t.raw
}
// Serialize turns this object into a map[string]interface{}.
func (t *Link) Serialize() (m map[string]interface{}, err error) {
return t.raw.Serialize()
}
// LenAttributedTo returns the number of values this property contains. Each index be used with HasAttributedTo to determine if GetAttributedTo is safe to call or if raw handling would be needed.
func (t *Link) LenAttributedTo() (idx int) {
return t.raw.AttributedToLen()
}
// GetAttributedTo attempts to get this 'attributedTo' property as a *url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetAttributedTo(idx int) (r Resolution, k *url.URL) {
r = Unresolved
handled := false
if t.raw.IsAttributedToIRI(idx) {
k = t.raw.GetAttributedToIRI(idx)
if handled {
r = Resolved
}
} else if t.raw.IsAttributedToObject(idx) {
r = RawResolutionNeeded
} else if t.raw.IsAttributedToLink(idx) {
r = RawResolutionNeeded
}
return
}
// AppendAttributedTo appends the value for property 'attributedTo'.
func (t *Link) AppendAttributedTo(k *url.URL) {
t.raw.AppendAttributedToIRI(k)
}
// PrependAttributedTo prepends the value for property 'attributedTo'.
func (t *Link) PrependAttributedTo(k *url.URL) {
t.raw.PrependAttributedToIRI(k)
}
// RemoveAttributedTo deletes the value from the specified index for property 'attributedTo'.
func (t *Link) RemoveAttributedTo(idx int) {
t.raw.RemoveAttributedToIRI(idx)
}
// HasAttributedTo returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasAttributedTo(idx int) (p Presence) {
p = NoPresence
if t.raw.IsAttributedToIRI(idx) {
p = ConvenientPresence
} else if t.raw.IsAttributedToLink(idx) {
p = RawPresence
} else if t.raw.IsAttributedToIRI(idx) {
p = RawPresence
}
return
}
// GetHref attempts to get this 'href' property as a *url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetHref() (r Resolution, k *url.URL) {
r = Unresolved
handled := false
if t.raw.HasHref() {
k = t.raw.GetHref()
if handled {
r = Resolved
}
}
return
}
// HasHref returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasHref() (p Presence) {
p = NoPresence
if t.raw.HasHref() {
p = ConvenientPresence
}
return
}
// SetHref sets the value for property 'href'.
func (t *Link) SetHref(k *url.URL) {
t.raw.SetHref(k)
}
// GetId attempts to get this 'id' property as a *url.URL. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetId() (r Resolution, k *url.URL) {
r = Unresolved
handled := false
if t.raw.HasId() {
k = t.raw.GetId()
if handled {
r = Resolved
}
}
return
}
// HasId returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasId() (p Presence) {
p = NoPresence
if t.raw.HasId() {
p = ConvenientPresence
}
return
}
// SetId sets the value for property 'id'.
func (t *Link) SetId(k *url.URL) {
t.raw.SetId(k)
}
// LenRel returns the number of values this property contains. Each index be used with HasRel to determine if GetRel is safe to call or if raw handling would be needed.
func (t *Link) LenRel() (idx int) {
return t.raw.RelLen()
}
// GetRel attempts to get this 'rel' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetRel(idx int) (r Resolution, k string) {
r = Unresolved
handled := false
if t.raw.IsRel(idx) {
k = t.raw.GetRel(idx)
if handled {
r = Resolved
}
} else if t.raw.IsRelIRI(idx) {
r = RawResolutionNeeded
}
return
}
// AppendRel appends the value for property 'rel'.
func (t *Link) AppendRel(k string) {
t.raw.AppendRel(k)
}
// PrependRel prepends the value for property 'rel'.
func (t *Link) PrependRel(k string) {
t.raw.PrependRel(k)
}
// RemoveRel deletes the value from the specified index for property 'rel'.
func (t *Link) RemoveRel(idx int) {
t.raw.RemoveRel(idx)
}
// HasRel returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasRel(idx int) (p Presence) {
p = NoPresence
if t.raw.IsRel(idx) {
p = ConvenientPresence
} else if t.raw.IsRelIRI(idx) {
p = RawPresence
}
return
}
// LenType returns the number of values this property contains. Each index be used with HasType to determine if GetType is safe to call or if raw handling would be needed.
func (t *Link) LenType() (idx int) {
return t.raw.TypeLen()
}
// GetType attempts to get this 'type' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetType(idx int) (r Resolution, s string) {
r = Unresolved
if tmp := t.raw.GetType(idx); tmp != nil {
ok := false
if s, ok = tmp.(string); ok {
r = Resolved
} else {
r = RawResolutionNeeded
}
}
return
}
// AppendType appends the value for property 'type'.
func (t *Link) AppendType(i interface{}) {
t.raw.AppendType(i)
}
// PrependType prepends the value for property 'type'.
func (t *Link) PrependType(i interface{}) {
t.raw.PrependType(i)
}
// RemoveType deletes the value from the specified index for property 'type'.
func (t *Link) RemoveType(idx int) {
t.raw.RemoveType(idx)
}
// GetMediaType attempts to get this 'mediaType' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetMediaType() (r Resolution, k string) {
r = Unresolved
handled := false
if t.raw.IsMediaType() {
k = t.raw.GetMediaType()
if handled {
r = Resolved
}
} else if t.raw.IsMediaTypeIRI() {
r = RawResolutionNeeded
}
return
}
// HasMediaType returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasMediaType() (p Presence) {
p = NoPresence
if t.raw.IsMediaType() {
p = ConvenientPresence
} else if t.raw.IsMediaTypeIRI() {
p = RawPresence
}
return
}
// SetMediaType sets the value for property 'mediaType'.
func (t *Link) SetMediaType(k string) {
t.raw.SetMediaType(k)
}
// LenName returns the number of values this property contains. Each index be used with HasName to determine if GetName is safe to call or if raw handling would be needed.
func (t *Link) LenName() (idx int) {
return t.raw.NameLen()
}
// GetName attempts to get this 'name' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetName(idx int) (r Resolution, k string) {
r = Unresolved
handled := false
if t.raw.IsNameString(idx) {
k = t.raw.GetNameString(idx)
if handled {
r = Resolved
}
} else if t.raw.IsNameLangString(idx) {
r = RawResolutionNeeded
} else if t.raw.IsNameIRI(idx) {
r = RawResolutionNeeded
}
return
}
// AppendName appends the value for property 'name'.
func (t *Link) AppendName(k string) {
t.raw.AppendNameString(k)
}
// PrependName prepends the value for property 'name'.
func (t *Link) PrependName(k string) {
t.raw.PrependNameString(k)
}
// RemoveName deletes the value from the specified index for property 'name'.
func (t *Link) RemoveName(idx int) {
t.raw.RemoveNameString(idx)
}
// HasName returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasName(idx int) (p Presence) {
p = NoPresence
if t.raw.IsNameString(idx) {
p = ConvenientPresence
} else if t.raw.IsNameLangString(idx) {
p = RawPresence
} else if t.raw.IsNameIRI(idx) {
p = RawPresence
}
return
}
// NameLanguages returns all languages for this property's language mapping, or nil if there are none.
func (t *Link) NameLanguages() (l []string) {
return t.raw.NameMapLanguages()
}
// GetNameMap retrieves the value of 'name' for the specified language, or an empty string if it does not exist
func (t *Link) GetNameForLanguage(l string) (v string) {
return t.raw.GetNameMap(l)
}
// SetNameForLanguage sets the value of 'name' for the specified language
func (t *Link) SetNameForLanguage(l string, v string) {
t.raw.SetNameMap(l, v)
}
// LenSummary returns the number of values this property contains. Each index be used with HasSummary to determine if GetSummary is safe to call or if raw handling would be needed.
func (t *Link) LenSummary() (idx int) {
return t.raw.SummaryLen()
}
// GetSummary attempts to get this 'summary' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetSummary(idx int) (r Resolution, k string) {
r = Unresolved
handled := false
if t.raw.IsSummaryString(idx) {
k = t.raw.GetSummaryString(idx)
if handled {
r = Resolved
}
} else if t.raw.IsSummaryLangString(idx) {
r = RawResolutionNeeded
} else if t.raw.IsSummaryIRI(idx) {
r = RawResolutionNeeded
}
return
}
// AppendSummary appends the value for property 'summary'.
func (t *Link) AppendSummary(k string) {
t.raw.AppendSummaryString(k)
}
// PrependSummary prepends the value for property 'summary'.
func (t *Link) PrependSummary(k string) {
t.raw.PrependSummaryString(k)
}
// RemoveSummary deletes the value from the specified index for property 'summary'.
func (t *Link) RemoveSummary(idx int) {
t.raw.RemoveSummaryString(idx)
}
// HasSummary returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasSummary(idx int) (p Presence) {
p = NoPresence
if t.raw.IsSummaryString(idx) {
p = ConvenientPresence
} else if t.raw.IsSummaryLangString(idx) {
p = RawPresence
} else if t.raw.IsSummaryIRI(idx) {
p = RawPresence
}
return
}
// SummaryLanguages returns all languages for this property's language mapping, or nil if there are none.
func (t *Link) SummaryLanguages() (l []string) {
return t.raw.SummaryMapLanguages()
}
// GetSummaryMap retrieves the value of 'summary' for the specified language, or an empty string if it does not exist
func (t *Link) GetSummaryForLanguage(l string) (v string) {
return t.raw.GetSummaryMap(l)
}
// SetSummaryForLanguage sets the value of 'summary' for the specified language
func (t *Link) SetSummaryForLanguage(l string, v string) {
t.raw.SetSummaryMap(l, v)
}
// GetHreflang attempts to get this 'hreflang' property as a string. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetHreflang() (r Resolution, k string) {
r = Unresolved
handled := false
if t.raw.IsHreflang() {
k = t.raw.GetHreflang()
if handled {
r = Resolved
}
} else if t.raw.IsHreflangIRI() {
r = RawResolutionNeeded
}
return
}
// HasHreflang returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasHreflang() (p Presence) {
p = NoPresence
if t.raw.IsHreflang() {
p = ConvenientPresence
} else if t.raw.IsHreflangIRI() {
p = RawPresence
}
return
}
// SetHreflang sets the value for property 'hreflang'.
func (t *Link) SetHreflang(k string) {
t.raw.SetHreflang(k)
}
// GetHeight attempts to get this 'height' property as a int64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetHeight() (r Resolution, k int64) {
r = Unresolved
handled := false
if t.raw.IsHeight() {
k = t.raw.GetHeight()
if handled {
r = Resolved
}
} else if t.raw.IsHeightIRI() {
r = RawResolutionNeeded
}
return
}
// HasHeight returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasHeight() (p Presence) {
p = NoPresence
if t.raw.IsHeight() {
p = ConvenientPresence
} else if t.raw.IsHeightIRI() {
p = RawPresence
}
return
}
// SetHeight sets the value for property 'height'.
func (t *Link) SetHeight(k int64) {
t.raw.SetHeight(k)
}
// GetWidth attempts to get this 'width' property as a int64. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling.
func (t *Link) GetWidth() (r Resolution, k int64) {
r = Unresolved
handled := false
if t.raw.IsWidth() {
k = t.raw.GetWidth()
if handled {
r = Resolved
}
} else if t.raw.IsWidthIRI() {
r = RawResolutionNeeded
}
return
}
// HasWidth returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasWidth() (p Presence) {
p = NoPresence
if t.raw.IsWidth() {
p = ConvenientPresence
} else if t.raw.IsWidthIRI() {
p = RawPresence
}
return
}
// SetWidth sets the value for property 'width'.
func (t *Link) SetWidth(k int64) {
t.raw.SetWidth(k)
}
// LenPreview returns the number of values this property contains. Each index be used with HasPreview to determine if ResolvePreview is safe to call or if raw handling would be needed.
func (t *Link) LenPreview() (idx int) {
return t.raw.PreviewLen()
}
// ResolvePreview passes the actual concrete type to the resolver for handing property preview. It returns a Resolution appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) ResolvePreview(r *Resolver, idx int) (s Resolution, err error) {
s = Unresolved
handled := false
if t.raw.IsPreviewObject(idx) {
handled, err = r.dispatch(t.raw.GetPreviewObject(idx))
if handled {
s = Resolved
}
} else if t.raw.IsPreviewLink(idx) {
handled, err = r.dispatch(t.raw.GetPreviewLink(idx))
if handled {
s = Resolved
}
} else if t.raw.IsPreviewIRI(idx) {
s = RawResolutionNeeded
}
return
}
// HasPreview returns a Presence appropriate for clients to determine whether it would be necessary to do raw handling, if desired.
func (t *Link) HasPreview(idx int) (p Presence) {
p = NoPresence
if t.raw.IsPreviewObject(idx) {
p = ConvenientPresence
} else if t.raw.IsPreviewLink(idx) {
p = ConvenientPresence
} else if t.raw.IsPreviewIRI(idx) {
p = RawPresence
}
return
}
// AppendPreview appends an 'Object' typed value.
func (t *Link) AppendPreview(i vocab.ObjectType) {
t.raw.AppendPreviewObject(i)
}
// PrependPreview prepends an 'Object' typed value.
func (t *Link) PrependPreview(i vocab.ObjectType) {
t.raw.PrependPreviewObject(i)
}
// AppendPreviewLink appends a 'Link' typed value.
func (t *Link) AppendPreviewLink(i vocab.LinkType) {
t.raw.AppendPreviewLink(i)
}
// PrependPreviewLink prepends a 'Link' typed value.
func (t *Link) PrependPreviewLink(i vocab.LinkType) {
t.raw.PrependPreviewLink(i)
}
// NewLink returns a new instance of Link
func NewLink() (n *Link) {
return &Link{raw: &vocab.Link{}}
}