...
1
2
3
4
5
6
7
8
9
10
11
12
13 package fs
14
15 import (
16 "bytes"
17 "context"
18 "encoding/json"
19 "errors"
20 "io"
21 "net/http"
22
23 "github.com/go-kivik/kivik/v4/driver"
24 )
25
26
27
28
29
30
31
32
33
34 func (d *db) Get(_ context.Context, docID string, options driver.Options) (*driver.Document, error) {
35 opts := map[string]interface{}{}
36 options.Apply(opts)
37 if docID == "" {
38 return nil, statusError{status: http.StatusBadRequest, error: errors.New("no docid specified")}
39 }
40 docs, err := d.cdb.OpenDocIDOpenRevs(docID, options)
41 if err != nil {
42 return nil, err
43 }
44 docs[0].Options = opts
45 buf := &bytes.Buffer{}
46 if err := json.NewEncoder(buf).Encode(docs[0]); err != nil {
47 return nil, err
48 }
49 attsIter, err := docs[0].Revisions[0].AttachmentsIterator()
50 if err != nil {
51 return nil, err
52 }
53 return &driver.Document{
54 Rev: docs[0].Revisions[0].Rev.String(),
55 Body: io.NopCloser(buf),
56 Attachments: attsIter,
57 }, nil
58 }
59
View as plain text