forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhead_attachment_command.go
83 lines (67 loc) · 1.97 KB
/
head_attachment_command.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package ravendb
import (
"net/http"
)
var (
_ RavenCommand = &HeadAttachmentCommand{}
)
type HeadAttachmentCommand struct {
RavenCommandBase
_documentID string
_name string
_changeVector *string
Result string // TODO: should this be *string?
}
func NewHeadAttachmentCommand(documentID string, name string, changeVector *string) (*HeadAttachmentCommand, error) {
if stringIsBlank(documentID) {
return nil, newIllegalArgumentError("DocumentId cannot be null or empty")
}
if stringIsBlank(name) {
return nil, newIllegalArgumentError("Name cannot be null or empty")
}
cmd := &HeadAttachmentCommand{
RavenCommandBase: NewRavenCommandBase(),
_documentID: documentID,
_name: name,
_changeVector: changeVector,
}
return cmd, nil
}
func (c *HeadAttachmentCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/attachments?id=" + urlUtilsEscapeDataString(c._documentID) + "&name=" + urlUtilsEscapeDataString(c._name)
request, err := newHttpGet(url)
if err != nil {
return nil, err
}
if c._changeVector != nil {
request.Header.Set(headersIfNoneMatch, *c._changeVector)
}
return request, nil
}
func (c *HeadAttachmentCommand) processResponse(cache *httpCache, response *http.Response, url string) (responseDisposeHandling, error) {
if response.StatusCode == http.StatusNotModified {
if c._changeVector != nil {
c.Result = *c._changeVector
}
return responseDisposeHandlingAutomatic, nil
}
if response.StatusCode == http.StatusNotFound {
c.Result = ""
return responseDisposeHandlingAutomatic, nil
}
res, err := gttpExtensionsGetRequiredEtagHeader(response)
if err != nil {
return responseDisposeHandlingAutomatic, err
}
if res != nil {
c.Result = *res
}
return responseDisposeHandlingAutomatic, nil
}
func (c *HeadAttachmentCommand) SetResponse(response []byte, fromCache bool) error {
if response != nil {
return throwInvalidResponse()
}
c.Result = ""
return nil
}