-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_fetch.go
61 lines (53 loc) · 1.86 KB
/
document_fetch.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
61
package couchdb
// // DocumentFetchRequest defines the document fetch request.
// type DocumentFetchRequest struct {
// document *DocumentRef
// id string
// ctx context.Context
// revision string
// }
// // WithContext adds a context to the request.
// func (dfr *DocumentFetchRequest) WithContext(ctx context.Context) *DocumentFetchRequest {
// dfr.ctx = ctx
// return dfr
// }
// // WithRevision adds a revision to the request.
// func (dfr *DocumentFetchRequest) WithRevision(revision string) *DocumentFetchRequest {
// dfr.revision = revision
// return dfr
// }
// // Do performs the request.
// func (dfr *DocumentFetchRequest) Do() (*DocumentFetchResponse, error) {
// request, err := dfr.document.database.client.requestFor(dfr.ctx, nil, http.MethodGet, dfr.document.database.name, dfr.id)
// if err != nil {
// return nil, err
// }
// request.Header.Set("Content-Type", MimeTypeJSON)
// request.Header.Set("Accept", MimeTypeJSON)
// if dfr.revision != "" {
// request.Header.Set("If-None-Match", dfr.revision)
// }
// response, err := dfr.document.database.client.do(request)
// if err != nil {
// return nil, errx.Annotatef(err, "request [%s] [%s]", request.Method, request.URL)
// }
// defer response.Body.Close()
// r := &DocumentFetchResponse{
// Revision: strings.Trim(response.Header.Get("ETag"), `"`),
// }
// if err := json.NewDecoder(response.Body).Decode(&r.Document); err != nil {
// return nil, errx.Annotatef(err, "json decode")
// }
// if err := evaluateResponseStatus(response.StatusCode, "",
// http.StatusOK,
// http.StatusNotModified,
// http.StatusBadRequest, http.StatusUnauthorized, http.StatusNotFound); err != nil {
// return r, err
// }
// return r, nil
// }
// // DocumentFetchResponse defines the document create response.
// type DocumentFetchResponse struct {
// Revision string
// Document Document
// }