ENCODED REVISION LISTS (_revisions): Parses a CouchDB _rev or _revisions property into a list of revision IDs
(ctx context.Context, body Body)
| 785 | |
| 786 | // Parses a CouchDB _rev or _revisions property into a list of revision IDs |
| 787 | func ParseRevisions(ctx context.Context, body Body) []string { |
| 788 | // http://wiki.apache.org/couchdb/HTTP_Document_API#GET |
| 789 | |
| 790 | revisionsProperty, ok := body[BodyRevisions] |
| 791 | if !ok { |
| 792 | revid, ok := body[BodyRev].(string) |
| 793 | if !ok { |
| 794 | return nil |
| 795 | } |
| 796 | if genOfRevID(ctx, revid) < 1 { |
| 797 | return nil |
| 798 | } |
| 799 | oneRev := make([]string, 0, 1) |
| 800 | oneRev = append(oneRev, revid) |
| 801 | return oneRev |
| 802 | } |
| 803 | |
| 804 | // Revisions may be stored in a Body as Revisions or map[string]interface{}, depending on the source of the Body |
| 805 | var revisions Revisions |
| 806 | switch revs := revisionsProperty.(type) { |
| 807 | case Revisions: |
| 808 | revisions = revs |
| 809 | case map[string]interface{}: |
| 810 | revisions = Revisions(revs) |
| 811 | default: |
| 812 | return nil |
| 813 | } |
| 814 | |
| 815 | return revisions.ParseRevisions() |
| 816 | } |
| 817 | |
| 818 | // Splits out the "start" and "ids" properties from encoded revision list |
| 819 | func splitRevisionList(revisions Revisions) (int, []string) { |