Accessors for document properties. To support lazy unmarshalling of document contents, all access should be done through accessors
(ctx context.Context)
| 369 | |
| 370 | // Accessors for document properties. To support lazy unmarshalling of document contents, all access should be done through accessors |
| 371 | func (doc *Document) Body(ctx context.Context) Body { |
| 372 | var caller string |
| 373 | if base.ConsoleLogLevel().Enabled(base.LevelTrace) { |
| 374 | caller = base.GetCallersName(1, true) |
| 375 | } |
| 376 | |
| 377 | if doc._body != nil { |
| 378 | base.TracefCtx(ctx, base.KeyAll, "Already had doc body %s/%s from %s", base.UD(doc.ID), base.UD(doc.RevID), caller) |
| 379 | return doc._body |
| 380 | } |
| 381 | |
| 382 | if doc._rawBody == nil { |
| 383 | return nil |
| 384 | } |
| 385 | |
| 386 | base.TracefCtx(ctx, base.KeyAll, " UNMARSHAL doc body %s/%s from %s", base.UD(doc.ID), base.UD(doc.RevID), caller) |
| 387 | err := doc._body.Unmarshal(doc._rawBody) |
| 388 | if err != nil { |
| 389 | base.WarnfCtx(ctx, "Unable to unmarshal document body from raw body : %s", err) |
| 390 | return nil |
| 391 | } |
| 392 | return doc._body |
| 393 | } |
| 394 | |
| 395 | // Get a deep mutable copy of the body, using _rawBody. Initializes _rawBody based on _body if not already present. |
| 396 | func (doc *Document) GetDeepMutableBody() (Body, error) { |