forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext_identity_for_command.go
56 lines (44 loc) · 1.05 KB
/
next_identity_for_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
package ravendb
import (
"net/http"
)
var (
_ RavenCommand = &NextIdentityForCommand{}
)
type NextIdentityForCommand struct {
RavenCommandBase
_id string
Result int
}
func NewNextIdentityForCommand(id string) *NextIdentityForCommand {
res := &NextIdentityForCommand{
RavenCommandBase: NewRavenCommandBase(),
_id: id,
}
panicIf(id == "", "Id cannot be null")
return res
}
func (c *NextIdentityForCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
err := ensureIsNotNullOrString(c._id, "ID")
if err != nil {
return nil, err
}
url := node.URL + "/databases/" + node.Database + "/identity/next?name=" + urlEncode(c._id)
return NewHttpPost(url, nil)
}
func (c *NextIdentityForCommand) SetResponse(response []byte, fromCache bool) error {
if len(response) == 0 {
return throwInvalidResponse()
}
var jsonNode map[string]interface{}
err := jsonUnmarshal(response, &jsonNode)
if err != nil {
return err
}
n, ok := jsonGetAsInt(jsonNode, "NewIdentityValue")
if !ok {
return throwInvalidResponse()
}
c.Result = n
return nil
}