forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed_identity_for_command.go
67 lines (53 loc) · 1.26 KB
/
seed_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
57
58
59
60
61
62
63
64
65
66
67
package ravendb
import (
"net/http"
)
var (
_ RavenCommand = &SeedIdentityForCommand{}
)
type SeedIdentityForCommand struct {
RavenCommandBase
id string
value int64
forced bool
Result int
}
func NewSeedIdentityForCommand(id string, value int64, forced bool) (*SeedIdentityForCommand, error) {
if id == "" {
return nil, newIllegalArgumentError("Id cannot be null")
}
res := &SeedIdentityForCommand{
RavenCommandBase: NewRavenCommandBase(),
id: id,
value: value,
forced: forced,
}
return res, nil
}
func (c *SeedIdentityForCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
err := ensureIsNotNullOrString(c.id, "ID")
if err != nil {
return nil, err
}
url := node.URL + "/databases/" + node.Database + "/identity/seed?name=" + urlEncode(c.id) + "&value=" + i64toa(c.value)
if c.forced {
url += "&force=true"
}
return NewHttpPost(url, nil)
}
func (c *SeedIdentityForCommand) 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, "NewSeedValue")
if !ok {
return throwInvalidResponse()
}
c.Result = n
return nil
}