forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathput_document_command.go
52 lines (41 loc) · 1.12 KB
/
put_document_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
package ravendb
import (
"net/http"
)
var (
_ RavenCommand = &PutDocumentCommand{}
)
type PutDocumentCommand struct {
RavenCommandBase
_id string
_changeVector *string
_document map[string]interface{}
Result *PutResult
}
func NewPutDocumentCommand(id string, changeVector *string, document map[string]interface{}) *PutDocumentCommand {
panicIf(id == "", "Id cannot be null")
panicIf(document == nil, "document cannot be nil")
cmd := &PutDocumentCommand{
RavenCommandBase: NewRavenCommandBase(),
_id: id,
_changeVector: changeVector,
_document: document,
}
return cmd
}
func (c *PutDocumentCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases/" + node.Database + "/docs?id=" + urlEncode(c._id)
d, err := jsonMarshal(c._document)
if err != nil {
return nil, err
}
request, err := newHttpPut(url, d)
if err != nil {
return nil, err
}
addChangeVectorIfNotNull(c._changeVector, request)
return request, nil
}
func (c *PutDocumentCommand) SetResponse(response []byte, fromCache bool) error {
return jsonUnmarshal(response, &c.Result)
}