1// Package vocab provides an implementation of serializing and deserializing activity streams into native golang structs without relying on reflection. This package is code-generated from the vocabulary specification available at https://www.w3.org/TR/activitystreams-vocabulary and by design forgoes full resolution of raw JSON-LD data. However, custom extensions of the vocabulary are supported by modifying the data definitions in the generation tool and rerunning it. Do not modify this package directly. 2package vocab 3 4import ( 5 "fmt" 6 "math" 7 "net/url" 8 "regexp" 9 "strconv" 10 "time" 11) 12 13// Serializer implementations can serialize themselves to a generic map form. 14type Serializer interface { 15 Serialize() (m map[string]interface{}, e error) 16} 17 18// Deserializer implementations can deserialize themselves from a generic map form. 19type Deserializer interface { 20 Deserialize(m map[string]interface{}) (e error) 21} 22 23// Typer supports common functions for determining an ActivityStream type 24type Typer interface { 25 TypeLen() (l int) 26 GetType(index int) (v interface{}) 27} 28 29// Unknown is an entry whose root type is unknown. 30type Unknown struct { 31 // Raw unknown, untyped values 32 u map[string]interface{} 33} 34 35// Serialize turns this object into a map[string]interface{}. Note that for the Unknown type, the "type" property is NOT populated with anything special during this process. 36func (t *Unknown) Serialize() (m map[string]interface{}, err error) { 37 m = t.u 38 return 39 40} 41 42// Deserialize populates this object from a map[string]interface{} 43func (t *Unknown) Deserialize(m map[string]interface{}) (err error) { 44 t.u = m 45 return 46 47} 48 49// HasField determines whether the call to GetField is safe with the specified field 50func (t *Unknown) HasField(f string) (ok bool) { 51 return t.u != nil && t.u[f] != nil 52 53} 54 55// GetField returns the unknown field value 56func (t *Unknown) GetField(f string) (v interface{}) { 57 return t.u[f] 58} 59 60// SetField sets the unknown field value 61func (t *Unknown) SetField(f string, i interface{}) (this *Unknown) { 62 if t.u == nil { 63 t.u = make(map[string]interface{}) 64 } 65 t.u[f] = i 66 return t 67 68} 69 70// dateTimeDeserialize turns a string into a time. 71func dateTimeDeserialize(v interface{}) (t *time.Time, err error) { 72 var tmp time.Time 73 if s, ok := v.(string); ok { 74 tmp, err = time.Parse(time.RFC3339, s) 75 if err != nil { 76 tmp, err = time.Parse("2006-01-02T15:04Z07:00", s) 77 if err != nil { 78 err = fmt.Errorf("%s cannot be interpreted as xsd:dateTime", s) 79 } else { 80 t = &tmp 81 } 82 } else { 83 t = &tmp 84 } 85 } else { 86 err = fmt.Errorf("%v cannot be interpreted as a string for xsd:dateTime", v) 87 } 88 return 89 90} 91 92// dateTimeSerialize turns a time into a string 93func dateTimeSerialize(t time.Time) (s string) { 94 s = t.Format(time.RFC3339) 95 return 96 97} 98 99// booleanDeserialize turns a interface{} into a bool. 100func booleanDeserialize(v interface{}) (b *bool, err error) { 101 if bv, ok := v.(bool); ok { 102 b = &bv 103 } else if bv, ok := v.(float64); ok { 104 if bv == 0 { 105 bvb := false 106 b = &bvb 107 } else if bv == 1 { 108 bvb := true 109 b = &bvb 110 } else { 111 err = fmt.Errorf("%d cannot be interpreted as a bool float64 for xsd:boolean", v) 112 } 113 } else { 114 err = fmt.Errorf("%v cannot be interpreted as a bool for xsd:boolean", v) 115 } 116 return 117 118} 119 120// booleanSerialize simply returns the bool value 121func booleanSerialize(v bool) (r bool) { 122 r = v 123 return 124 125} 126 127// anyURIDeserialize turns a string into a URI. 128func anyURIDeserialize(v interface{}) (u *url.URL, err error) { 129 if s, ok := v.(string); ok { 130 u, err = url.Parse(s) 131 if err != nil { 132 err = fmt.Errorf("%s cannot be interpreted as xsd:anyURI", s) 133 } 134 } else { 135 err = fmt.Errorf("%v cannot be interpreted as a string for xsd:anyURI", v) 136 } 137 return 138 139} 140 141// anyURISerialize turns a URI into a string 142func anyURISerialize(u *url.URL) (s string) { 143 s = u.String() 144 return 145 146} 147 148// floatDeserialize turns a interface{} into a float64. 149func floatDeserialize(v interface{}) (f *float64, err error) { 150 if fv, ok := v.(float64); ok { 151 f = &fv 152 } else { 153 err = fmt.Errorf("%v cannot be interpreted as a float for xsd:float", v) 154 } 155 return 156 157} 158 159// floatSerialize simply returns the float value 160func floatSerialize(f float64) (r float64) { 161 r = f 162 return 163 164} 165 166// stringDeserialize turns a interface{} into a string. 167func stringDeserialize(v interface{}) (s *string, err error) { 168 if sv, ok := v.(string); ok { 169 s = &sv 170 } else { 171 err = fmt.Errorf("%v cannot be interpreted as a string for xsd:string", v) 172 } 173 return 174 175} 176 177// stringSerialize simply returns the string value 178func stringSerialize(s string) (r string) { 179 r = s 180 return 181 182} 183 184// langStringDeserialize turns a RDF interface{} into a string. 185func langStringDeserialize(v interface{}) (s *string, err error) { 186 if sv, ok := v.(string); ok { 187 s = &sv 188 } else { 189 err = fmt.Errorf("%v cannot be interpreted as a string for rdf:langString", v) 190 } 191 return 192 193} 194 195// langStringSerialize returns a formatted RDF value. 196func langStringSerialize(s string) (r string) { 197 r = s 198 return 199 200} 201 202// durationDeserialize turns a interface{} into a time.Duration. 203func durationDeserialize(v interface{}) (d *time.Duration, err error) { 204 if sv, ok := v.(string); ok { 205 isNeg := false 206 if sv[0] == '-' { 207 isNeg = true 208 sv = sv[1:] 209 } 210 if sv[0] != 'P' { 211 err = fmt.Errorf("'%s' malformed: missing 'P' for xsd:duration", sv) 212 return 213 } 214 re := regexp.MustCompile("P(\\d*Y)?(\\d*M)?(\\d*D)?(T(\\d*H)?(\\d*M)?(\\d*S)?)?") 215 res := re.FindStringSubmatch(sv) 216 var dur time.Duration 217 nYear := res[1] 218 if len(nYear) > 0 { 219 nYear = nYear[:len(nYear)-1] 220 vYear, err := strconv.ParseInt(nYear, 10, 64) 221 if err != nil { 222 return nil, err 223 } 224 dur += time.Duration(vYear) * time.Hour * 8760 // Hours per 365 days -- no way to count leap years here. 225 } 226 nMonth := res[2] 227 if len(nMonth) > 0 { 228 nMonth = nMonth[:len(nMonth)-1] 229 vMonth, err := strconv.ParseInt(nMonth, 10, 64) 230 if err != nil { 231 return nil, err 232 } 233 dur += time.Duration(vMonth) * time.Hour * 720 // Hours per 30 days -- no way to tell if these months span 31 days, 28, or 29 each. 234 } 235 nDay := res[3] 236 if len(nDay) > 0 { 237 nDay = nDay[:len(nDay)-1] 238 vDay, err := strconv.ParseInt(nDay, 10, 64) 239 if err != nil { 240 return nil, err 241 } 242 dur += time.Duration(vDay) * time.Hour * 24 243 } 244 nHour := res[5] 245 if len(nHour) > 0 { 246 nHour = nHour[:len(nHour)-1] 247 vHour, err := strconv.ParseInt(nHour, 10, 64) 248 if err != nil { 249 return nil, err 250 } 251 dur += time.Duration(vHour) * time.Hour 252 } 253 nMinute := res[6] 254 if len(nMinute) > 0 { 255 nMinute = nMinute[:len(nMinute)-1] 256 vMinute, err := strconv.ParseInt(nMinute, 10, 64) 257 if err != nil { 258 return nil, err 259 } 260 dur += time.Duration(vMinute) * time.Minute 261 } 262 nSecond := res[7] 263 if len(nSecond) > 0 { 264 nSecond = nSecond[:len(nSecond)-1] 265 vSecond, err := strconv.ParseInt(nSecond, 10, 64) 266 if err != nil { 267 return nil, err 268 } 269 dur += time.Duration(vSecond) * time.Second 270 } 271 if isNeg { 272 dur *= -1 273 } 274 d = &dur 275 } else { 276 err = fmt.Errorf("%v cannot be interpreted as a string for xsd:duration", v) 277 } 278 return 279 280} 281 282// durationSerialize returns the duration as a string. 283func durationSerialize(d time.Duration) (s string) { 284 s = "P" 285 if d < 0 { 286 s = "-P" 287 d = -1 * d 288 } 289 var tally time.Duration 290 if years := d.Hours() / 8760.0; years >= 1 { 291 nYears := int64(math.Floor(years)) 292 tally += time.Duration(nYears) * 8760 * time.Hour 293 s = fmt.Sprintf("%s%dY", s, nYears) 294 } 295 if months := (d.Hours() - tally.Hours()) / 720.0; months >= 1 { 296 nMonths := int64(math.Floor(months)) 297 tally += time.Duration(nMonths) * 720 * time.Hour 298 s = fmt.Sprintf("%s%dM", s, nMonths) 299 } 300 if days := (d.Hours() - tally.Hours()) / 24.0; days >= 1 { 301 nDays := int64(math.Floor(days)) 302 tally += time.Duration(nDays) * 24 * time.Hour 303 s = fmt.Sprintf("%s%dD", s, nDays) 304 } 305 if tally < d { 306 s = fmt.Sprintf("%sT", s) 307 if hours := d.Hours() - tally.Hours(); hours >= 1 { 308 nHours := int64(math.Floor(hours)) 309 tally += time.Duration(nHours) * time.Hour 310 s = fmt.Sprintf("%s%dH", s, nHours) 311 } 312 if minutes := d.Minutes() - tally.Minutes(); minutes >= 1 { 313 nMinutes := int64(math.Floor(minutes)) 314 tally += time.Duration(nMinutes) * time.Minute 315 s = fmt.Sprintf("%s%dM", s, nMinutes) 316 } 317 if seconds := d.Seconds() - tally.Seconds(); seconds >= 1 { 318 nSeconds := int64(math.Floor(seconds)) 319 tally += time.Duration(nSeconds) * time.Second 320 s = fmt.Sprintf("%s%dS", s, nSeconds) 321 } 322 } 323 return 324 325} 326 327// nonNegativeIntegerDeserialize turns a interface{} into a positive int64 value. 328func nonNegativeIntegerDeserialize(v interface{}) (i *int64, err error) { 329 if fv, ok := v.(float64); ok { 330 iv := int64(fv) 331 if iv >= 0 { 332 i = &iv 333 } else { 334 err = fmt.Errorf("%d is a negative integer for xsd:nonNegativeInteger", iv) 335 } 336 } else { 337 err = fmt.Errorf("%v cannot be interpreted as a float for xsd:nonNegativeInteger", v) 338 } 339 return 340 341} 342 343// nonNegativeIntegerSerialize simply returns the int64 value. 344func nonNegativeIntegerSerialize(i int64) (r int64) { 345 r = i 346 return 347 348} 349 350// bcp47LanguageTagDeserialize turns a interface{} into a string. 351func bcp47LanguageTagDeserialize(v interface{}) (s *string, err error) { 352 if sv, ok := v.(string); ok { 353 s = &sv 354 } else { 355 err = fmt.Errorf("%v cannot be interpreted as a string for BCP 47 Language Tag", v) 356 } 357 return 358 359} 360 361// bcp47LanguageTagSerialize simply returns the string value 362func bcp47LanguageTagSerialize(s string) (r string) { 363 r = s 364 return 365 366} 367 368// mimeMediaTypeValueDeserialize turns a interface{} into a string. 369func mimeMediaTypeValueDeserialize(v interface{}) (s *string, err error) { 370 if sv, ok := v.(string); ok { 371 s = &sv 372 } else { 373 err = fmt.Errorf("%v cannot be interpreted as a string for MIME media type value", v) 374 } 375 return 376 377} 378 379// mimeMediaTypeValueSerialize simply returns the string value 380func mimeMediaTypeValueSerialize(s string) (r string) { 381 r = s 382 return 383 384} 385 386// linkRelationDeserialize turns a interface{} into a string. 387func linkRelationDeserialize(v interface{}) (s *string, err error) { 388 if sv, ok := v.(string); ok { 389 s = &sv 390 } else { 391 err = fmt.Errorf("%v cannot be interpreted as a string for link relation", v) 392 } 393 return 394 395} 396 397// linkRelationSerialize simply returns the string value 398func linkRelationSerialize(s string) (r string) { 399 r = s 400 return 401 402} 403 404// unitsValueDeserialize turns a interface{} into a string. 405func unitsValueDeserialize(v interface{}) (s *string, err error) { 406 if sv, ok := v.(string); ok { 407 s = &sv 408 } else { 409 err = fmt.Errorf("%v cannot be interpreted as a string for units value", v) 410 } 411 return 412 413} 414 415// unitsValueSerialize simply returns the string value 416func unitsValueSerialize(s string) (r string) { 417 r = s 418 return 419 420} 421 422// IRIDeserialize turns a string into a URI. 423func IRIDeserialize(v interface{}) (u *url.URL, err error) { 424 if s, ok := v.(string); ok { 425 u, err = url.Parse(s) 426 if err != nil { 427 err = fmt.Errorf("%s cannot be interpreted as IRI", s) 428 } 429 } else { 430 err = fmt.Errorf("%v cannot be interpreted as a string for IRI", v) 431 } 432 return 433 434} 435 436// IRISerialize turns an IRI into a string 437func IRISerialize(u *url.URL) (s string) { 438 s = u.String() 439 return 440 441} 442 443// HasTypeObject returns true if the Typer has a type of Object. 444func HasTypeObject(t Typer) (b bool) { 445 for i := 0; i < t.TypeLen(); i++ { 446 v := t.GetType(i) 447 if s, ok := v.(string); ok { 448 if s == "Object" { 449 return true 450 } 451 } 452 } 453 return false 454 455} 456 457// HasTypeLink returns true if the Typer has a type of Link. 458func HasTypeLink(t Typer) (b bool) { 459 for i := 0; i < t.TypeLen(); i++ { 460 v := t.GetType(i) 461 if s, ok := v.(string); ok { 462 if s == "Link" { 463 return true 464 } 465 } 466 } 467 return false 468 469} 470 471// HasTypeActivity returns true if the Typer has a type of Activity. 472func HasTypeActivity(t Typer) (b bool) { 473 for i := 0; i < t.TypeLen(); i++ { 474 v := t.GetType(i) 475 if s, ok := v.(string); ok { 476 if s == "Activity" { 477 return true 478 } 479 } 480 } 481 return false 482 483} 484 485// HasTypeIntransitiveActivity returns true if the Typer has a type of IntransitiveActivity. 486func HasTypeIntransitiveActivity(t Typer) (b bool) { 487 for i := 0; i < t.TypeLen(); i++ { 488 v := t.GetType(i) 489 if s, ok := v.(string); ok { 490 if s == "IntransitiveActivity" { 491 return true 492 } 493 } 494 } 495 return false 496 497} 498 499// HasTypeCollection returns true if the Typer has a type of Collection. 500func HasTypeCollection(t Typer) (b bool) { 501 for i := 0; i < t.TypeLen(); i++ { 502 v := t.GetType(i) 503 if s, ok := v.(string); ok { 504 if s == "Collection" { 505 return true 506 } 507 } 508 } 509 return false 510 511} 512 513// HasTypeOrderedCollection returns true if the Typer has a type of OrderedCollection. 514func HasTypeOrderedCollection(t Typer) (b bool) { 515 for i := 0; i < t.TypeLen(); i++ { 516 v := t.GetType(i) 517 if s, ok := v.(string); ok { 518 if s == "OrderedCollection" { 519 return true 520 } 521 } 522 } 523 return false 524 525} 526 527// HasTypeCollectionPage returns true if the Typer has a type of CollectionPage. 528func HasTypeCollectionPage(t Typer) (b bool) { 529 for i := 0; i < t.TypeLen(); i++ { 530 v := t.GetType(i) 531 if s, ok := v.(string); ok { 532 if s == "CollectionPage" { 533 return true 534 } 535 } 536 } 537 return false 538 539} 540 541// HasTypeOrderedCollectionPage returns true if the Typer has a type of OrderedCollectionPage. 542func HasTypeOrderedCollectionPage(t Typer) (b bool) { 543 for i := 0; i < t.TypeLen(); i++ { 544 v := t.GetType(i) 545 if s, ok := v.(string); ok { 546 if s == "OrderedCollectionPage" { 547 return true 548 } 549 } 550 } 551 return false 552 553} 554 555// HasTypeAccept returns true if the Typer has a type of Accept. 556func HasTypeAccept(t Typer) (b bool) { 557 for i := 0; i < t.TypeLen(); i++ { 558 v := t.GetType(i) 559 if s, ok := v.(string); ok { 560 if s == "Accept" { 561 return true 562 } 563 } 564 } 565 return false 566 567} 568 569// HasTypeTentativeAccept returns true if the Typer has a type of TentativeAccept. 570func HasTypeTentativeAccept(t Typer) (b bool) { 571 for i := 0; i < t.TypeLen(); i++ { 572 v := t.GetType(i) 573 if s, ok := v.(string); ok { 574 if s == "TentativeAccept" { 575 return true 576 } 577 } 578 } 579 return false 580 581} 582 583// HasTypeAdd returns true if the Typer has a type of Add. 584func HasTypeAdd(t Typer) (b bool) { 585 for i := 0; i < t.TypeLen(); i++ { 586 v := t.GetType(i) 587 if s, ok := v.(string); ok { 588 if s == "Add" { 589 return true 590 } 591 } 592 } 593 return false 594 595} 596 597// HasTypeArrive returns true if the Typer has a type of Arrive. 598func HasTypeArrive(t Typer) (b bool) { 599 for i := 0; i < t.TypeLen(); i++ { 600 v := t.GetType(i) 601 if s, ok := v.(string); ok { 602 if s == "Arrive" { 603 return true 604 } 605 } 606 } 607 return false 608 609} 610 611// HasTypeCreate returns true if the Typer has a type of Create. 612func HasTypeCreate(t Typer) (b bool) { 613 for i := 0; i < t.TypeLen(); i++ { 614 v := t.GetType(i) 615 if s, ok := v.(string); ok { 616 if s == "Create" { 617 return true 618 } 619 } 620 } 621 return false 622 623} 624 625// HasTypeDelete returns true if the Typer has a type of Delete. 626func HasTypeDelete(t Typer) (b bool) { 627 for i := 0; i < t.TypeLen(); i++ { 628 v := t.GetType(i) 629 if s, ok := v.(string); ok { 630 if s == "Delete" { 631 return true 632 } 633 } 634 } 635 return false 636 637} 638 639// HasTypeFollow returns true if the Typer has a type of Follow. 640func HasTypeFollow(t Typer) (b bool) { 641 for i := 0; i < t.TypeLen(); i++ { 642 v := t.GetType(i) 643 if s, ok := v.(string); ok { 644 if s == "Follow" { 645 return true 646 } 647 } 648 } 649 return false 650 651} 652 653// HasTypeIgnore returns true if the Typer has a type of Ignore. 654func HasTypeIgnore(t Typer) (b bool) { 655 for i := 0; i < t.TypeLen(); i++ { 656 v := t.GetType(i) 657 if s, ok := v.(string); ok { 658 if s == "Ignore" { 659 return true 660 } 661 } 662 } 663 return false 664 665} 666 667// HasTypeJoin returns true if the Typer has a type of Join. 668func HasTypeJoin(t Typer) (b bool) { 669 for i := 0; i < t.TypeLen(); i++ { 670 v := t.GetType(i) 671 if s, ok := v.(string); ok { 672 if s == "Join" { 673 return true 674 } 675 } 676 } 677 return false 678 679} 680 681// HasTypeLeave returns true if the Typer has a type of Leave. 682func HasTypeLeave(t Typer) (b bool) { 683 for i := 0; i < t.TypeLen(); i++ { 684 v := t.GetType(i) 685 if s, ok := v.(string); ok { 686 if s == "Leave" { 687 return true 688 } 689 } 690 } 691 return false 692 693} 694 695// HasTypeLike returns true if the Typer has a type of Like. 696func HasTypeLike(t Typer) (b bool) { 697 for i := 0; i < t.TypeLen(); i++ { 698 v := t.GetType(i) 699 if s, ok := v.(string); ok { 700 if s == "Like" { 701 return true 702 } 703 } 704 } 705 return false 706 707} 708 709// HasTypeOffer returns true if the Typer has a type of Offer. 710func HasTypeOffer(t Typer) (b bool) { 711 for i := 0; i < t.TypeLen(); i++ { 712 v := t.GetType(i) 713 if s, ok := v.(string); ok { 714 if s == "Offer" { 715 return true 716 } 717 } 718 } 719 return false 720 721} 722 723// HasTypeInvite returns true if the Typer has a type of Invite. 724func HasTypeInvite(t Typer) (b bool) { 725 for i := 0; i < t.TypeLen(); i++ { 726 v := t.GetType(i) 727 if s, ok := v.(string); ok { 728 if s == "Invite" { 729 return true 730 } 731 } 732 } 733 return false 734 735} 736 737// HasTypeReject returns true if the Typer has a type of Reject. 738func HasTypeReject(t Typer) (b bool) { 739 for i := 0; i < t.TypeLen(); i++ { 740 v := t.GetType(i) 741 if s, ok := v.(string); ok { 742 if s == "Reject" { 743 return true 744 } 745 } 746 } 747 return false 748 749} 750 751// HasTypeTentativeReject returns true if the Typer has a type of TentativeReject. 752func HasTypeTentativeReject(t Typer) (b bool) { 753 for i := 0; i < t.TypeLen(); i++ { 754 v := t.GetType(i) 755 if s, ok := v.(string); ok { 756 if s == "TentativeReject" { 757 return true 758 } 759 } 760 } 761 return false 762 763} 764 765// HasTypeRemove returns true if the Typer has a type of Remove. 766func HasTypeRemove(t Typer) (b bool) { 767 for i := 0; i < t.TypeLen(); i++ { 768 v := t.GetType(i) 769 if s, ok := v.(string); ok { 770 if s == "Remove" { 771 return true 772 } 773 } 774 } 775 return false 776 777} 778 779// HasTypeUndo returns true if the Typer has a type of Undo. 780func HasTypeUndo(t Typer) (b bool) { 781 for i := 0; i < t.TypeLen(); i++ { 782 v := t.GetType(i) 783 if s, ok := v.(string); ok { 784 if s == "Undo" { 785 return true 786 } 787 } 788 } 789 return false 790 791} 792 793// HasTypeUpdate returns true if the Typer has a type of Update. 794func HasTypeUpdate(t Typer) (b bool) { 795 for i := 0; i < t.TypeLen(); i++ { 796 v := t.GetType(i) 797 if s, ok := v.(string); ok { 798 if s == "Update" { 799 return true 800 } 801 } 802 } 803 return false 804 805} 806 807// HasTypeView returns true if the Typer has a type of View. 808func HasTypeView(t Typer) (b bool) { 809 for i := 0; i < t.TypeLen(); i++ { 810 v := t.GetType(i) 811 if s, ok := v.(string); ok { 812 if s == "View" { 813 return true 814 } 815 } 816 } 817 return false 818 819} 820 821// HasTypeListen returns true if the Typer has a type of Listen. 822func HasTypeListen(t Typer) (b bool) { 823 for i := 0; i < t.TypeLen(); i++ { 824 v := t.GetType(i) 825 if s, ok := v.(string); ok { 826 if s == "Listen" { 827 return true 828 } 829 } 830 } 831 return false 832 833} 834 835// HasTypeRead returns true if the Typer has a type of Read. 836func HasTypeRead(t Typer) (b bool) { 837 for i := 0; i < t.TypeLen(); i++ { 838 v := t.GetType(i) 839 if s, ok := v.(string); ok { 840 if s == "Read" { 841 return true 842 } 843 } 844 } 845 return false 846 847} 848 849// HasTypeMove returns true if the Typer has a type of Move. 850func HasTypeMove(t Typer) (b bool) { 851 for i := 0; i < t.TypeLen(); i++ { 852 v := t.GetType(i) 853 if s, ok := v.(string); ok { 854 if s == "Move" { 855 return true 856 } 857 } 858 } 859 return false 860 861} 862 863// HasTypeTravel returns true if the Typer has a type of Travel. 864func HasTypeTravel(t Typer) (b bool) { 865 for i := 0; i < t.TypeLen(); i++ { 866 v := t.GetType(i) 867 if s, ok := v.(string); ok { 868 if s == "Travel" { 869 return true 870 } 871 } 872 } 873 return false 874 875} 876 877// HasTypeAnnounce returns true if the Typer has a type of Announce. 878func HasTypeAnnounce(t Typer) (b bool) { 879 for i := 0; i < t.TypeLen(); i++ { 880 v := t.GetType(i) 881 if s, ok := v.(string); ok { 882 if s == "Announce" { 883 return true 884 } 885 } 886 } 887 return false 888 889} 890 891// HasTypeBlock returns true if the Typer has a type of Block. 892func HasTypeBlock(t Typer) (b bool) { 893 for i := 0; i < t.TypeLen(); i++ { 894 v := t.GetType(i) 895 if s, ok := v.(string); ok { 896 if s == "Block" { 897 return true 898 } 899 } 900 } 901 return false 902 903} 904 905// HasTypeFlag returns true if the Typer has a type of Flag. 906func HasTypeFlag(t Typer) (b bool) { 907 for i := 0; i < t.TypeLen(); i++ { 908 v := t.GetType(i) 909 if s, ok := v.(string); ok { 910 if s == "Flag" { 911 return true 912 } 913 } 914 } 915 return false 916 917} 918 919// HasTypeDislike returns true if the Typer has a type of Dislike. 920func HasTypeDislike(t Typer) (b bool) { 921 for i := 0; i < t.TypeLen(); i++ { 922 v := t.GetType(i) 923 if s, ok := v.(string); ok { 924 if s == "Dislike" { 925 return true 926 } 927 } 928 } 929 return false 930 931} 932 933// HasTypeQuestion returns true if the Typer has a type of Question. 934func HasTypeQuestion(t Typer) (b bool) { 935 for i := 0; i < t.TypeLen(); i++ { 936 v := t.GetType(i) 937 if s, ok := v.(string); ok { 938 if s == "Question" { 939 return true 940 } 941 } 942 } 943 return false 944 945} 946 947// HasTypeApplication returns true if the Typer has a type of Application. 948func HasTypeApplication(t Typer) (b bool) { 949 for i := 0; i < t.TypeLen(); i++ { 950 v := t.GetType(i) 951 if s, ok := v.(string); ok { 952 if s == "Application" { 953 return true 954 } 955 } 956 } 957 return false 958 959} 960 961// HasTypeGroup returns true if the Typer has a type of Group. 962func HasTypeGroup(t Typer) (b bool) { 963 for i := 0; i < t.TypeLen(); i++ { 964 v := t.GetType(i) 965 if s, ok := v.(string); ok { 966 if s == "Group" { 967 return true 968 } 969 } 970 } 971 return false 972 973} 974 975// HasTypeOrganization returns true if the Typer has a type of Organization. 976func HasTypeOrganization(t Typer) (b bool) { 977 for i := 0; i < t.TypeLen(); i++ { 978 v := t.GetType(i) 979 if s, ok := v.(string); ok { 980 if s == "Organization" { 981 return true 982 } 983 } 984 } 985 return false 986 987} 988 989// HasTypePerson returns true if the Typer has a type of Person. 990func HasTypePerson(t Typer) (b bool) { 991 for i := 0; i < t.TypeLen(); i++ { 992 v := t.GetType(i) 993 if s, ok := v.(string); ok { 994 if s == "Person" { 995 return true 996 } 997 } 998 } 999 return false 1000 1001} 1002 1003// HasTypeService returns true if the Typer has a type of Service. 1004func HasTypeService(t Typer) (b bool) { 1005 for i := 0; i < t.TypeLen(); i++ { 1006 v := t.GetType(i) 1007 if s, ok := v.(string); ok { 1008 if s == "Service" { 1009 return true 1010 } 1011 } 1012 } 1013 return false 1014 1015} 1016 1017// HasTypeRelationship returns true if the Typer has a type of Relationship. 1018func HasTypeRelationship(t Typer) (b bool) { 1019 for i := 0; i < t.TypeLen(); i++ { 1020 v := t.GetType(i) 1021 if s, ok := v.(string); ok { 1022 if s == "Relationship" { 1023 return true 1024 } 1025 } 1026 } 1027 return false 1028 1029} 1030 1031// HasTypeArticle returns true if the Typer has a type of Article. 1032func HasTypeArticle(t Typer) (b bool) { 1033 for i := 0; i < t.TypeLen(); i++ { 1034 v := t.GetType(i) 1035 if s, ok := v.(string); ok { 1036 if s == "Article" { 1037 return true 1038 } 1039 } 1040 } 1041 return false 1042 1043} 1044 1045// HasTypeDocument returns true if the Typer has a type of Document. 1046func HasTypeDocument(t Typer) (b bool) { 1047 for i := 0; i < t.TypeLen(); i++ { 1048 v := t.GetType(i) 1049 if s, ok := v.(string); ok { 1050 if s == "Document" { 1051 return true 1052 } 1053 } 1054 } 1055 return false 1056 1057} 1058 1059// HasTypeAudio returns true if the Typer has a type of Audio. 1060func HasTypeAudio(t Typer) (b bool) { 1061 for i := 0; i < t.TypeLen(); i++ { 1062 v := t.GetType(i) 1063 if s, ok := v.(string); ok { 1064 if s == "Audio" { 1065 return true 1066 } 1067 } 1068 } 1069 return false 1070 1071} 1072 1073// HasTypeImage returns true if the Typer has a type of Image. 1074func HasTypeImage(t Typer) (b bool) { 1075 for i := 0; i < t.TypeLen(); i++ { 1076 v := t.GetType(i) 1077 if s, ok := v.(string); ok { 1078 if s == "Image" { 1079 return true 1080 } 1081 } 1082 } 1083 return false 1084 1085} 1086 1087// HasTypeVideo returns true if the Typer has a type of Video. 1088func HasTypeVideo(t Typer) (b bool) { 1089 for i := 0; i < t.TypeLen(); i++ { 1090 v := t.GetType(i) 1091 if s, ok := v.(string); ok { 1092 if s == "Video" { 1093 return true 1094 } 1095 } 1096 } 1097 return false 1098 1099} 1100 1101// HasTypeNote returns true if the Typer has a type of Note. 1102func HasTypeNote(t Typer) (b bool) { 1103 for i := 0; i < t.TypeLen(); i++ { 1104 v := t.GetType(i) 1105 if s, ok := v.(string); ok { 1106 if s == "Note" { 1107 return true 1108 } 1109 } 1110 } 1111 return false 1112 1113} 1114 1115// HasTypePage returns true if the Typer has a type of Page. 1116func HasTypePage(t Typer) (b bool) { 1117 for i := 0; i < t.TypeLen(); i++ { 1118 v := t.GetType(i) 1119 if s, ok := v.(string); ok { 1120 if s == "Page" { 1121 return true 1122 } 1123 } 1124 } 1125 return false 1126 1127} 1128 1129// HasTypeEvent returns true if the Typer has a type of Event. 1130func HasTypeEvent(t Typer) (b bool) { 1131 for i := 0; i < t.TypeLen(); i++ { 1132 v := t.GetType(i) 1133 if s, ok := v.(string); ok { 1134 if s == "Event" { 1135 return true 1136 } 1137 } 1138 } 1139 return false 1140 1141} 1142 1143// HasTypePlace returns true if the Typer has a type of Place. 1144func HasTypePlace(t Typer) (b bool) { 1145 for i := 0; i < t.TypeLen(); i++ { 1146 v := t.GetType(i) 1147 if s, ok := v.(string); ok { 1148 if s == "Place" { 1149 return true 1150 } 1151 } 1152 } 1153 return false 1154 1155} 1156 1157// HasTypeProfile returns true if the Typer has a type of Profile. 1158func HasTypeProfile(t Typer) (b bool) { 1159 for i := 0; i < t.TypeLen(); i++ { 1160 v := t.GetType(i) 1161 if s, ok := v.(string); ok { 1162 if s == "Profile" { 1163 return true 1164 } 1165 } 1166 } 1167 return false 1168 1169} 1170 1171// HasTypeTombstone returns true if the Typer has a type of Tombstone. 1172func HasTypeTombstone(t Typer) (b bool) { 1173 for i := 0; i < t.TypeLen(); i++ { 1174 v := t.GetType(i) 1175 if s, ok := v.(string); ok { 1176 if s == "Tombstone" { 1177 return true 1178 } 1179 } 1180 } 1181 return false 1182 1183} 1184 1185// HasTypeMention returns true if the Typer has a type of Mention. 1186func HasTypeMention(t Typer) (b bool) { 1187 for i := 0; i < t.TypeLen(); i++ { 1188 v := t.GetType(i) 1189 if s, ok := v.(string); ok { 1190 if s == "Mention" { 1191 return true 1192 } 1193 } 1194 } 1195 return false 1196 1197} 1198 1199// Returns true if the provided Typer is an Activity. 1200func IsActivityType(t Typer) (b bool) { 1201 var activityTypes = []string{"IntransitiveActivity", "Accept", "TentativeAccept", "Add", "Arrive", "Create", "Delete", "Follow", "Ignore", "Join", "Leave", "Like", "Offer", "Invite", "Reject", "TentativeReject", "Remove", "Undo", "Update", "View", "Listen", "Read", "Move", "Travel", "Announce", "Block", "Flag", "Dislike", "Question"} 1202 hasType := make(map[string]bool, 1) 1203 for i := 0; i < t.TypeLen(); i++ { 1204 v := t.GetType(i) 1205 if s, ok := v.(string); ok { 1206 hasType[s] = true 1207 } 1208 } 1209 for _, t := range activityTypes { 1210 if hasType[t] { 1211 return true 1212 } 1213 } 1214 return false 1215 1216} 1217 1218// resolveObject turns a string type that extends Object into a concrete type. 1219func resolveObject(s string) (i interface{}) { 1220 if s == "Object" { 1221 return &Object{} 1222 } 1223 if s == "Activity" { 1224 return &Activity{} 1225 } 1226 if s == "IntransitiveActivity" { 1227 return &IntransitiveActivity{} 1228 } 1229 if s == "Collection" { 1230 return &Collection{} 1231 } 1232 if s == "OrderedCollection" { 1233 return &OrderedCollection{} 1234 } 1235 if s == "CollectionPage" { 1236 return &CollectionPage{} 1237 } 1238 if s == "OrderedCollectionPage" { 1239 return &OrderedCollectionPage{} 1240 } 1241 if s == "Accept" { 1242 return &Accept{} 1243 } 1244 if s == "TentativeAccept" { 1245 return &TentativeAccept{} 1246 } 1247 if s == "Add" { 1248 return &Add{} 1249 } 1250 if s == "Arrive" { 1251 return &Arrive{} 1252 } 1253 if s == "Create" { 1254 return &Create{} 1255 } 1256 if s == "Delete" { 1257 return &Delete{} 1258 } 1259 if s == "Follow" { 1260 return &Follow{} 1261 } 1262 if s == "Ignore" { 1263 return &Ignore{} 1264 } 1265 if s == "Join" { 1266 return &Join{} 1267 } 1268 if s == "Leave" { 1269 return &Leave{} 1270 } 1271 if s == "Like" { 1272 return &Like{} 1273 } 1274 if s == "Offer" { 1275 return &Offer{} 1276 } 1277 if s == "Invite" { 1278 return &Invite{} 1279 } 1280 if s == "Reject" { 1281 return &Reject{} 1282 } 1283 if s == "TentativeReject" { 1284 return &TentativeReject{} 1285 } 1286 if s == "Remove" { 1287 return &Remove{} 1288 } 1289 if s == "Undo" { 1290 return &Undo{} 1291 } 1292 if s == "Update" { 1293 return &Update{} 1294 } 1295 if s == "View" { 1296 return &View{} 1297 } 1298 if s == "Listen" { 1299 return &Listen{} 1300 } 1301 if s == "Read" { 1302 return &Read{} 1303 } 1304 if s == "Move" { 1305 return &Move{} 1306 } 1307 if s == "Travel" { 1308 return &Travel{} 1309 } 1310 if s == "Announce" { 1311 return &Announce{} 1312 } 1313 if s == "Block" { 1314 return &Block{} 1315 } 1316 if s == "Flag" { 1317 return &Flag{} 1318 } 1319 if s == "Dislike" { 1320 return &Dislike{} 1321 } 1322 if s == "Question" { 1323 return &Question{} 1324 } 1325 if s == "Application" { 1326 return &Application{} 1327 } 1328 if s == "Group" { 1329 return &Group{} 1330 } 1331 if s == "Organization" { 1332 return &Organization{} 1333 } 1334 if s == "Person" { 1335 return &Person{} 1336 } 1337 if s == "Service" { 1338 return &Service{} 1339 } 1340 if s == "Relationship" { 1341 return &Relationship{} 1342 } 1343 if s == "Article" { 1344 return &Article{} 1345 } 1346 if s == "Document" { 1347 return &Document{} 1348 } 1349 if s == "Audio" { 1350 return &Audio{} 1351 } 1352 if s == "Image" { 1353 return &Image{} 1354 } 1355 if s == "Video" { 1356 return &Video{} 1357 } 1358 if s == "Note" { 1359 return &Note{} 1360 } 1361 if s == "Page" { 1362 return &Page{} 1363 } 1364 if s == "Event" { 1365 return &Event{} 1366 } 1367 if s == "Place" { 1368 return &Place{} 1369 } 1370 if s == "Profile" { 1371 return &Profile{} 1372 } 1373 if s == "Tombstone" { 1374 return &Tombstone{} 1375 } 1376 return nil 1377 1378} 1379 1380// resolveLink turns a string type that extends Link into a concrete type. 1381func resolveLink(s string) (i interface{}) { 1382 if s == "Link" { 1383 return &Link{} 1384 } 1385 if s == "Mention" { 1386 return &Mention{} 1387 } 1388 return nil 1389 1390} 1391 1392// unknownValueDeserialize transparently stores the object. 1393func unknownValueDeserialize(v interface{}) (o interface{}) { 1394 o = v 1395 return 1396 1397} 1398 1399// unknownValueSerialize transparently returns the object. 1400func unknownValueSerialize(v interface{}) (o interface{}) { 1401 o = v 1402 return 1403 1404} 1405