forked from zemirco/couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.go
60 lines (52 loc) · 1.67 KB
/
document.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
package couchdb
// CouchDoc describes interface for every couchdb document.
type CouchDoc interface {
GetID() string
GetRev() string
}
// Document is base struct which should be embedded by any other couchdb document.
type Document struct {
ID string `json:"_id,omitempty"`
Rev string `json:"_rev,omitempty"`
Attachments map[string]Attachment `json:"_attachments,omitempty"`
}
// Attachment describes attachments of a document.
// http://docs.couchdb.org/en/stable/api/document/common.html#attachments
// By using attachments you are also able to upload a document in multipart/related format.
// http://docs.couchdb.org/en/latest/api/document/common.html#creating-multiple-attachments
type Attachment struct {
ContentType string `json:"content_type,omitempty"`
Data string `json:"data,omitempty"`
Digest string `json:"digest,omitempty"`
EncodedLength float64 `json:"encoded_length,omitempty"`
Encoding string `json:"encoding,omitempty"`
Length int64 `json:"length,omitempty"`
RevPos float64 `json:"revpos,omitempty"`
Stub bool `json:"stub,omitempty"`
Follows bool `json:"follows,omitempty"`
}
// GetID returns document id
func (d *Document) GetID() string {
return d.ID
}
// GetRev returns document revision
func (d *Document) GetRev() string {
return d.Rev
}
type ArbitraryDoc map[string]interface{}
func (a ArbitraryDoc) GetID() string {
if idI, ok := a["_id"]; ok {
if id, ok := idI.(string); ok {
return id
}
}
return ""
}
func (a ArbitraryDoc) GetRev() string {
if revI, ok := a["_rev"]; ok {
if rev, ok := revI.(string); ok {
return rev
}
}
return ""
}