forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext_hi_lo_command.go
54 lines (45 loc) · 1.62 KB
/
next_hi_lo_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
package ravendb
import (
"net/http"
"time"
)
var (
_ RavenCommand = &NextHiLoCommand{}
)
// NextHiLoCommand represents a hi-lo database command
type NextHiLoCommand struct {
RavenCommandBase
_tag string
_lastBatchSize int64
_lastRangeAt *time.Time // TODO: our Time?
_identityPartsSeparator string
_lastRangeMax int64
Result *HiLoResult
}
//NewNextHiLoCommand returns new NextHiLoCommand
func NewNextHiLoCommand(tag string, lastBatchSize int64, lastRangeAt *time.Time, identityPartsSeparator string, lastRangeMax int64) *NextHiLoCommand {
panicIf(tag == "", "tag cannot be empty")
panicIf(identityPartsSeparator == "", "identityPartsSeparator cannot be empty")
cmd := &NextHiLoCommand{
RavenCommandBase: NewRavenCommandBase(),
_tag: tag,
_lastBatchSize: lastBatchSize,
_lastRangeAt: lastRangeAt,
_identityPartsSeparator: identityPartsSeparator,
_lastRangeMax: lastRangeMax,
}
cmd.IsReadRequest = true
return cmd
}
func (c *NextHiLoCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
date := ""
if c._lastRangeAt != nil && !c._lastRangeAt.IsZero() {
date = (*c._lastRangeAt).Format(timeFormat)
}
path := "/hilo/next?tag=" + c._tag + "&lastBatchSize=" + i64toa(c._lastBatchSize) + "&lastRangeAt=" + date + "&identityPartsSeparator=" + c._identityPartsSeparator + "&lastMax=" + i64toa(c._lastRangeMax)
url := node.URL + "/databases/" + node.Database + path
return newHttpGet(url)
}
func (c *NextHiLoCommand) SetResponse(response []byte, fromCache bool) error {
return jsonUnmarshal(response, &c.Result)
}