github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/next_hi_lo_command.go (about)

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  )
     7  
     8  var (
     9  	_ RavenCommand = &NextHiLoCommand{}
    10  )
    11  
    12  // NextHiLoCommand represents a hi-lo database command
    13  type NextHiLoCommand struct {
    14  	RavenCommandBase
    15  
    16  	_tag                    string
    17  	_lastBatchSize          int64
    18  	_lastRangeAt            *time.Time // TODO: our Time?
    19  	_identityPartsSeparator string
    20  	_lastRangeMax           int64
    21  
    22  	Result *HiLoResult
    23  }
    24  
    25  //NewNextHiLoCommand returns new NextHiLoCommand
    26  func NewNextHiLoCommand(tag string, lastBatchSize int64, lastRangeAt *time.Time, identityPartsSeparator string, lastRangeMax int64) *NextHiLoCommand {
    27  	panicIf(tag == "", "tag cannot be empty")
    28  	panicIf(identityPartsSeparator == "", "identityPartsSeparator cannot be empty")
    29  	cmd := &NextHiLoCommand{
    30  		RavenCommandBase: NewRavenCommandBase(),
    31  
    32  		_tag:                    tag,
    33  		_lastBatchSize:          lastBatchSize,
    34  		_lastRangeAt:            lastRangeAt,
    35  		_identityPartsSeparator: identityPartsSeparator,
    36  		_lastRangeMax:           lastRangeMax,
    37  	}
    38  	cmd.IsReadRequest = true
    39  	return cmd
    40  }
    41  
    42  func (c *NextHiLoCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
    43  	date := ""
    44  	if c._lastRangeAt != nil && !c._lastRangeAt.IsZero() {
    45  		date = (*c._lastRangeAt).Format(timeFormat)
    46  	}
    47  	path := "/hilo/next?tag=" + c._tag + "&lastBatchSize=" + i64toa(c._lastBatchSize) + "&lastRangeAt=" + date + "&identityPartsSeparator=" + c._identityPartsSeparator + "&lastMax=" + i64toa(c._lastRangeMax)
    48  	url := node.URL + "/databases/" + node.Database + path
    49  	return newHttpGet(url)
    50  }
    51  
    52  func (c *NextHiLoCommand) SetResponse(response []byte, fromCache bool) error {
    53  	return jsonUnmarshal(response, &c.Result)
    54  }