| 1 |
package activitypub |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"encoding/gob" |
| 6 |
"encoding/json" |
| 7 |
"fmt" |
| 8 |
"time" |
| 9 |
|
| 10 |
"github.com/valyala/fastjson" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
const ( |
| 15 |
ApplicationType ActivityVocabularyType = "Application" |
| 16 |
GroupType ActivityVocabularyType = "Group" |
| 17 |
OrganizationType ActivityVocabularyType = "Organization" |
| 18 |
PersonType ActivityVocabularyType = "Person" |
| 19 |
ServiceType ActivityVocabularyType = "Service" |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
var ActorTypes = ActivityVocabularyTypes{ |
| 24 |
ApplicationType, |
| 25 |
GroupType, |
| 26 |
OrganizationType, |
| 27 |
PersonType, |
| 28 |
ServiceType, |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
type CanReceiveActivities Item |
| 36 |
|
| 37 |
type Actors interface { |
| 38 |
Actor |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
type Actor struct { |
| 46 |
|
| 47 |
ID ID `jsonld:"id,omitempty"` |
| 48 |
|
| 49 |
Type Typer `jsonld:"type,omitempty"` |
| 50 |
|
| 51 |
|
| 52 |
Name NaturalLanguageValues `jsonld:"name,omitempty,collapsible"` |
| 53 |
|
| 54 |
|
| 55 |
Attachment Item `jsonld:"attachment,omitempty"` |
| 56 |
|
| 57 |
|
| 58 |
AttributedTo Item `jsonld:"attributedTo,omitempty"` |
| 59 |
|
| 60 |
|
| 61 |
Audience ItemCollection `jsonld:"audience,omitempty"` |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
Content NaturalLanguageValues `jsonld:"content,omitempty,collapsible"` |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
Context Item `jsonld:"context,omitempty"` |
| 72 |
|
| 73 |
|
| 74 |
MediaType MimeType `jsonld:"mediaType,omitempty"` |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
EndTime time.Time `jsonld:"endTime,omitempty"` |
| 79 |
|
| 80 |
Generator Item `jsonld:"generator,omitempty"` |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
Icon Item `jsonld:"icon,omitempty"` |
| 85 |
|
| 86 |
|
| 87 |
Image Item `jsonld:"image,omitempty"` |
| 88 |
|
| 89 |
InReplyTo Item `jsonld:"inReplyTo,omitempty"` |
| 90 |
|
| 91 |
Location Item `jsonld:"location,omitempty"` |
| 92 |
|
| 93 |
Preview Item `jsonld:"preview,omitempty"` |
| 94 |
|
| 95 |
Published time.Time `jsonld:"published,omitempty"` |
| 96 |
|
| 97 |
Replies Item `jsonld:"replies,omitempty"` |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
StartTime time.Time `jsonld:"startTime,omitempty"` |
| 102 |
|
| 103 |
|
| 104 |
Summary NaturalLanguageValues `jsonld:"summary,omitempty,collapsible"` |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
Tag ItemCollection `jsonld:"tag,omitempty"` |
| 109 |
|
| 110 |
Updated time.Time `jsonld:"updated,omitempty"` |
| 111 |
|
| 112 |
URL Item `jsonld:"url,omitempty"` |
| 113 |
|
| 114 |
To ItemCollection `jsonld:"to,omitempty"` |
| 115 |
|
| 116 |
Bto ItemCollection `jsonld:"bto,omitempty"` |
| 117 |
|
| 118 |
CC ItemCollection `jsonld:"cc,omitempty"` |
| 119 |
|
| 120 |
BCC ItemCollection `jsonld:"bcc,omitempty"` |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
Duration time.Duration `jsonld:"duration,omitempty"` |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
Likes Item `jsonld:"likes,omitempty"` |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
Shares Item `jsonld:"shares,omitempty"` |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
Source Source `jsonld:"source,omitempty"` |
| 138 |
|
| 139 |
|
| 140 |
Inbox Item `jsonld:"inbox,omitempty"` |
| 141 |
|
| 142 |
|
| 143 |
Outbox Item `jsonld:"outbox,omitempty"` |
| 144 |
|
| 145 |
|
| 146 |
Following Item `jsonld:"following,omitempty"` |
| 147 |
|
| 148 |
|
| 149 |
Followers Item `jsonld:"followers,omitempty"` |
| 150 |
|
| 151 |
|
| 152 |
Liked Item `jsonld:"liked,omitempty"` |
| 153 |
|
| 154 |
PreferredUsername NaturalLanguageValues `jsonld:"preferredUsername,omitempty,collapsible"` |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
Endpoints *Endpoints `jsonld:"endpoints,omitempty"` |
| 160 |
|
| 161 |
Streams ItemCollection `jsonld:"streams,omitempty"` |
| 162 |
PublicKey PublicKey `jsonld:"publicKey,omitempty"` |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
func (a Actor) GetID() ID { |
| 167 |
return a.ID |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
func (a Actor) GetLink() IRI { |
| 172 |
return IRI(a.ID) |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
func (a Actor) GetType() Typer { |
| 177 |
return a.Type |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
func (a Actor) IsLink() bool { |
| 182 |
return false |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
func (a Actor) IsObject() bool { |
| 187 |
return true |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
func (a Actor) IsCollection() bool { |
| 192 |
return false |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
func (a Actor) Match(tt ...ActivityVocabularyType) bool { |
| 197 |
return ActivityVocabularyTypes(tt).Match(a.Type) |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
type PublicKey struct { |
| 204 |
ID ID `jsonld:"id,omitempty"` |
| 205 |
Owner IRI `jsonld:"owner,omitempty"` |
| 206 |
PublicKeyPem string `jsonld:"publicKeyPem,omitempty"` |
| 207 |
} |
| 208 |
|
| 209 |
func (p *PublicKey) UnmarshalJSON(data []byte) error { |
| 210 |
par := fastjson.Parser{} |
| 211 |
val, err := par.ParseBytes(data) |
| 212 |
if err != nil { |
| 213 |
return err |
| 214 |
} |
| 215 |
|
| 216 |
return JSONLoadPublicKey(val, p) |
| 217 |
} |
| 218 |
|
| 219 |
func (p PublicKey) MarshalJSON() ([]byte, error) { |
| 220 |
b := make([]byte, 0) |
| 221 |
notEmpty := true |
| 222 |
JSONWrite(&b, '{') |
| 223 |
if v, err := p.ID.MarshalJSON(); err == nil && len(v) > 0 { |
| 224 |
notEmpty = !JSONWriteProp(&b, "id", v) |
| 225 |
} |
| 226 |
if len(p.Owner) > 0 { |
| 227 |
notEmpty = JSONWriteIRIProp(&b, "owner", p.Owner) || notEmpty |
| 228 |
} |
| 229 |
if len(p.PublicKeyPem) > 0 { |
| 230 |
if pem, err := json.Marshal(p.PublicKeyPem); err == nil { |
| 231 |
notEmpty = JSONWriteProp(&b, "publicKeyPem", pem) || notEmpty |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
if notEmpty { |
| 236 |
JSONWrite(&b, '}') |
| 237 |
return b, nil |
| 238 |
} |
| 239 |
return nil, nil |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
func (a *Actor) UnmarshalBinary(data []byte) error { |
| 244 |
return a.GobDecode(data) |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
func (a Actor) MarshalBinary() ([]byte, error) { |
| 249 |
return a.GobEncode() |
| 250 |
} |
| 251 |
|
| 252 |
func (a Actor) GobEncode() ([]byte, error) { |
| 253 |
mm := make(map[string][]byte) |
| 254 |
hasData, err := mapActorProperties(mm, &a) |
| 255 |
if err != nil { |
| 256 |
return nil, err |
| 257 |
} |
| 258 |
if !hasData { |
| 259 |
return []byte{}, nil |
| 260 |
} |
| 261 |
bb := bytes.Buffer{} |
| 262 |
g := gob.NewEncoder(&bb) |
| 263 |
if err := g.Encode(mm); err != nil { |
| 264 |
return nil, err |
| 265 |
} |
| 266 |
return bb.Bytes(), nil |
| 267 |
} |
| 268 |
|
| 269 |
func (a *Actor) GobDecode(data []byte) error { |
| 270 |
if len(data) == 0 { |
| 271 |
return nil |
| 272 |
} |
| 273 |
mm, err := gobDecodeObjectAsMap(data) |
| 274 |
if err != nil { |
| 275 |
return err |
| 276 |
} |
| 277 |
return unmapActorProperties(mm, a) |
| 278 |
} |
| 279 |
|
| 280 |
type ( |
| 281 |
|
| 282 |
Application = Actor |
| 283 |
|
| 284 |
|
| 285 |
Group = Actor |
| 286 |
|
| 287 |
|
| 288 |
Organization = Actor |
| 289 |
|
| 290 |
|
| 291 |
Person = Actor |
| 292 |
|
| 293 |
|
| 294 |
Service = Actor |
| 295 |
) |
| 296 |
|
| 297 |
|
| 298 |
func ActorNew(id ID, typ ActivityVocabularyType) *Actor { |
| 299 |
if !ActorTypes.Match(typ) { |
| 300 |
typ = ActorType |
| 301 |
} |
| 302 |
|
| 303 |
a := Actor{ID: id, Type: typ} |
| 304 |
a.Name = NaturalLanguageValuesNew() |
| 305 |
a.Content = NaturalLanguageValuesNew() |
| 306 |
a.Summary = NaturalLanguageValuesNew() |
| 307 |
a.PreferredUsername = NaturalLanguageValuesNew() |
| 308 |
|
| 309 |
return &a |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
func ApplicationNew(id ID) *Application { |
| 314 |
a := ActorNew(id, ApplicationType) |
| 315 |
o := Application(*a) |
| 316 |
return &o |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
func GroupNew(id ID) *Group { |
| 321 |
a := ActorNew(id, GroupType) |
| 322 |
o := Group(*a) |
| 323 |
return &o |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
func OrganizationNew(id ID) *Organization { |
| 328 |
a := ActorNew(id, OrganizationType) |
| 329 |
o := Organization(*a) |
| 330 |
return &o |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
func PersonNew(id ID) *Person { |
| 335 |
a := ActorNew(id, PersonType) |
| 336 |
o := Person(*a) |
| 337 |
return &o |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
func ServiceNew(id ID) *Service { |
| 342 |
a := ActorNew(id, ServiceType) |
| 343 |
o := Service(*a) |
| 344 |
return &o |
| 345 |
} |
| 346 |
|
| 347 |
func (a *Actor) Recipients() ItemCollection { |
| 348 |
aud := a.Audience |
| 349 |
return ItemCollectionDeduplication(&a.To, &a.CC, &a.Bto, &a.BCC, &aud) |
| 350 |
} |
| 351 |
|
| 352 |
func (a *Actor) Clean() { |
| 353 |
_ = OnObject(a, func(o *Object) error { |
| 354 |
o.Clean() |
| 355 |
return nil |
| 356 |
}) |
| 357 |
} |
| 358 |
|
| 359 |
func (a *Actor) UnmarshalJSON(data []byte) error { |
| 360 |
p := fastjson.Parser{} |
| 361 |
val, err := p.ParseBytes(data) |
| 362 |
if err != nil { |
| 363 |
return err |
| 364 |
} |
| 365 |
return JSONLoadActor(val, a) |
| 366 |
} |
| 367 |
|
| 368 |
func (a Actor) MarshalJSON() ([]byte, error) { |
| 369 |
b := make([]byte, 0) |
| 370 |
notEmpty := false |
| 371 |
JSONWrite(&b, '{') |
| 372 |
|
| 373 |
_ = OnObject(a, func(o *Object) error { |
| 374 |
notEmpty = JSONWriteObjectValue(&b, *o) |
| 375 |
return nil |
| 376 |
}) |
| 377 |
if a.Inbox != nil { |
| 378 |
notEmpty = JSONWriteItemProp(&b, "inbox", a.Inbox) || notEmpty |
| 379 |
} |
| 380 |
if a.Outbox != nil { |
| 381 |
notEmpty = JSONWriteItemProp(&b, "outbox", a.Outbox) || notEmpty |
| 382 |
} |
| 383 |
if a.Following != nil { |
| 384 |
notEmpty = JSONWriteItemProp(&b, "following", a.Following) || notEmpty |
| 385 |
} |
| 386 |
if a.Followers != nil { |
| 387 |
notEmpty = JSONWriteItemProp(&b, "followers", a.Followers) || notEmpty |
| 388 |
} |
| 389 |
if a.Liked != nil { |
| 390 |
notEmpty = JSONWriteItemProp(&b, "liked", a.Liked) || notEmpty |
| 391 |
} |
| 392 |
if a.PreferredUsername != nil { |
| 393 |
notEmpty = JSONWriteNaturalLanguageProp(&b, "preferredUsername", a.PreferredUsername) || notEmpty |
| 394 |
} |
| 395 |
if a.Endpoints != nil { |
| 396 |
if v, err := a.Endpoints.MarshalJSON(); err == nil && len(v) > 0 { |
| 397 |
notEmpty = JSONWriteProp(&b, "endpoints", v) || notEmpty |
| 398 |
} |
| 399 |
} |
| 400 |
if len(a.Streams) > 0 { |
| 401 |
notEmpty = JSONWriteItemCollectionProp(&b, "streams", a.Streams, false) |
| 402 |
} |
| 403 |
if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 { |
| 404 |
if v, err := a.PublicKey.MarshalJSON(); err == nil && len(v) > 0 { |
| 405 |
notEmpty = JSONWriteProp(&b, "publicKey", v) || notEmpty |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
if notEmpty { |
| 410 |
JSONWrite(&b, '}') |
| 411 |
return b, nil |
| 412 |
} |
| 413 |
return nil, nil |
| 414 |
} |
| 415 |
|
| 416 |
func (a Actor) Format(s fmt.State, verb rune) { |
| 417 |
switch verb { |
| 418 |
case 's': |
| 419 |
if HasTypes(a) && a.ID != "" { |
| 420 |
_, _ = fmt.Fprintf(s, "%T[%s]( %s )", a, a.GetType(), a.ID) |
| 421 |
} else if a.ID != "" { |
| 422 |
_, _ = fmt.Fprintf(s, "%T( %s )", a, a.ID) |
| 423 |
} else { |
| 424 |
_, _ = fmt.Fprintf(s, "%T[%p]", a, &a) |
| 425 |
} |
| 426 |
case 'v': |
| 427 |
_, _ = fmt.Fprintf(s, "%T[%s] { }", a, a.Type) |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
type Endpoints struct { |
| 436 |
|
| 437 |
UploadMedia Item `jsonld:"uploadMedia,omitempty"` |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
OauthAuthorizationEndpoint Item `jsonld:"oauthAuthorizationEndpoint,omitempty"` |
| 442 |
|
| 443 |
|
| 444 |
OauthTokenEndpoint Item `jsonld:"oauthTokenEndpoint,omitempty"` |
| 445 |
|
| 446 |
|
| 447 |
ProvideClientKey Item `jsonld:"provideClientKey,omitempty"` |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
SignClientKey Item `jsonld:"signClientKey,omitempty"` |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
SharedInbox Item `jsonld:"sharedInbox,omitempty"` |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
ProxyURL IRI `jsonld:"proxyUrl,omitempty"` |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
func (e *Endpoints) UnmarshalJSON(data []byte) error { |
| 465 |
p := fastjson.Parser{} |
| 466 |
val, err := p.ParseBytes(data) |
| 467 |
if err != nil { |
| 468 |
return err |
| 469 |
} |
| 470 |
e.OauthAuthorizationEndpoint = JSONGetItem(val, "oauthAuthorizationEndpoint") |
| 471 |
e.OauthTokenEndpoint = JSONGetItem(val, "oauthTokenEndpoint") |
| 472 |
e.UploadMedia = JSONGetItem(val, "uploadMedia") |
| 473 |
e.ProvideClientKey = JSONGetItem(val, "provideClientKey") |
| 474 |
e.SignClientKey = JSONGetItem(val, "signClientKey") |
| 475 |
e.SharedInbox = JSONGetItem(val, "sharedInbox") |
| 476 |
return nil |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
func (e Endpoints) MarshalJSON() ([]byte, error) { |
| 481 |
b := make([]byte, 0) |
| 482 |
notEmpty := false |
| 483 |
|
| 484 |
JSONWrite(&b, '{') |
| 485 |
if e.OauthAuthorizationEndpoint != nil { |
| 486 |
notEmpty = JSONWriteItemProp(&b, "oauthAuthorizationEndpoint", e.OauthAuthorizationEndpoint) |
| 487 |
} |
| 488 |
if e.OauthTokenEndpoint != nil { |
| 489 |
notEmpty = JSONWriteItemProp(&b, "oauthTokenEndpoint", e.OauthTokenEndpoint) || notEmpty |
| 490 |
} |
| 491 |
if e.ProvideClientKey != nil { |
| 492 |
notEmpty = JSONWriteItemProp(&b, "provideClientKey", e.ProvideClientKey) || notEmpty |
| 493 |
} |
| 494 |
if e.SignClientKey != nil { |
| 495 |
notEmpty = JSONWriteItemProp(&b, "signClientKey", e.SignClientKey) || notEmpty |
| 496 |
} |
| 497 |
if e.SharedInbox != nil { |
| 498 |
notEmpty = JSONWriteItemProp(&b, "sharedInbox", e.SharedInbox) || notEmpty |
| 499 |
} |
| 500 |
if e.UploadMedia != nil { |
| 501 |
notEmpty = JSONWriteItemProp(&b, "uploadMedia", e.UploadMedia) || notEmpty |
| 502 |
} |
| 503 |
if notEmpty { |
| 504 |
JSONWrite(&b, '}') |
| 505 |
return b, nil |
| 506 |
} |
| 507 |
return nil, nil |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
func ToActor(it LinkOrIRI) (*Actor, error) { |
| 512 |
switch i := it.(type) { |
| 513 |
case *Actor: |
| 514 |
return i, nil |
| 515 |
case Actor: |
| 516 |
return &i, nil |
| 517 |
default: |
| 518 |
return reflectItemToType[Actor](it) |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
func (a *Actor) Equals(with Item) bool { |
| 524 |
if IsNil(with) { |
| 525 |
return a == nil |
| 526 |
} |
| 527 |
withActor, err := ToActor(with) |
| 528 |
if err != nil { |
| 529 |
return false |
| 530 |
} |
| 531 |
return a.equal(*withActor) |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
func (a Actor) equal(with Actor) bool { |
| 536 |
result := true |
| 537 |
|
| 538 |
_ = OnObject(a, func(oa *Object) error { |
| 539 |
result = oa.Equals(with) |
| 540 |
return nil |
| 541 |
}) |
| 542 |
if with.Inbox != nil { |
| 543 |
if !ItemsEqual(a.Inbox, with.Inbox) { |
| 544 |
result = false |
| 545 |
} |
| 546 |
} |
| 547 |
if with.Outbox != nil { |
| 548 |
if !ItemsEqual(a.Outbox, with.Outbox) { |
| 549 |
result = false |
| 550 |
} |
| 551 |
} |
| 552 |
if with.Liked != nil { |
| 553 |
if !ItemsEqual(a.Liked, with.Liked) { |
| 554 |
result = false |
| 555 |
} |
| 556 |
} |
| 557 |
if with.PreferredUsername != nil { |
| 558 |
if !a.PreferredUsername.Equal(with.PreferredUsername) { |
| 559 |
result = false |
| 560 |
} |
| 561 |
} |
| 562 |
return result |
| 563 |
} |
| 564 |
|
| 565 |
func (e Endpoints) GobEncode() ([]byte, error) { |
| 566 |
return nil, nil |
| 567 |
} |
| 568 |
|
| 569 |
func (e *Endpoints) GobDecode(data []byte) error { |
| 570 |
return nil |
| 571 |
} |
| 572 |
|
| 573 |
func (p PublicKey) GobEncode() ([]byte, error) { |
| 574 |
var ( |
| 575 |
mm = make(map[string][]byte) |
| 576 |
err error |
| 577 |
hasData bool |
| 578 |
) |
| 579 |
if len(p.ID) > 0 { |
| 580 |
if mm["id"], err = p.ID.GobEncode(); err != nil { |
| 581 |
return nil, err |
| 582 |
} |
| 583 |
hasData = true |
| 584 |
} |
| 585 |
if len(p.PublicKeyPem) > 0 { |
| 586 |
mm["publicKeyPem"] = []byte(p.PublicKeyPem) |
| 587 |
hasData = true |
| 588 |
} |
| 589 |
if len(p.Owner) > 0 { |
| 590 |
if mm["owner"], err = gobEncodeItem(p.Owner); err != nil { |
| 591 |
return nil, err |
| 592 |
} |
| 593 |
hasData = true |
| 594 |
} |
| 595 |
if !hasData { |
| 596 |
return []byte{}, nil |
| 597 |
} |
| 598 |
bb := bytes.Buffer{} |
| 599 |
g := gob.NewEncoder(&bb) |
| 600 |
if err := g.Encode(mm); err != nil { |
| 601 |
return nil, err |
| 602 |
} |
| 603 |
return bb.Bytes(), nil |
| 604 |
} |
| 605 |
|
| 606 |
func (p *PublicKey) GobDecode(data []byte) error { |
| 607 |
if len(data) == 0 { |
| 608 |
return nil |
| 609 |
} |
| 610 |
mm, err := gobDecodeObjectAsMap(data) |
| 611 |
if err != nil { |
| 612 |
return err |
| 613 |
} |
| 614 |
if raw, ok := mm["id"]; ok { |
| 615 |
if err = p.ID.GobDecode(raw); err != nil { |
| 616 |
return err |
| 617 |
} |
| 618 |
} |
| 619 |
if raw, ok := mm["owner"]; ok { |
| 620 |
if err = p.Owner.GobDecode(raw); err != nil { |
| 621 |
return err |
| 622 |
} |
| 623 |
} |
| 624 |
if raw, ok := mm["publicKeyPem"]; ok { |
| 625 |
p.PublicKeyPem = string(raw) |
| 626 |
} |
| 627 |
return nil |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
type WithActorFn func(*Actor) error |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
func OnActor(it LinkOrIRI, fn func(*Actor) error) error { |
| 639 |
if it == nil { |
| 640 |
return nil |
| 641 |
} |
| 642 |
if IsItemCollection(it) { |
| 643 |
return callOnItemCollection(it, OnActor, fn) |
| 644 |
} |
| 645 |
act, err := ToActor(it) |
| 646 |
if err != nil { |
| 647 |
return err |
| 648 |
} |
| 649 |
return fn(act) |
| 650 |
} |