github.com/altipla-consulting/ravendb-go-client@v0.1.3/delete_compare_exchange_value_operation.go (about)

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  	"reflect"
     6  )
     7  
     8  var (
     9  	_ IOperation = &DeleteCompareExchangeValueOperation{}
    10  )
    11  
    12  type DeleteCompareExchangeValueOperation struct {
    13  	Command *RemoveCompareExchangeValueCommand
    14  
    15  	_clazz reflect.Type
    16  	_key   string
    17  	_index int64
    18  }
    19  
    20  func NewDeleteCompareExchangeValueOperation(clazz reflect.Type, key string, index int64) (*DeleteCompareExchangeValueOperation, error) {
    21  	if stringIsEmpty(key) {
    22  		return nil, newIllegalArgumentError("The kye argument must have value")
    23  	}
    24  
    25  	return &DeleteCompareExchangeValueOperation{
    26  		_clazz: clazz,
    27  		_key:   key,
    28  		_index: index,
    29  	}, nil
    30  }
    31  
    32  func (o *DeleteCompareExchangeValueOperation) GetCommand(store *DocumentStore, conventions *DocumentConventions, cache *httpCache) (RavenCommand, error) {
    33  	var err error
    34  	o.Command, err = NewRemoveCompareExchangeValueCommand(o._clazz, o._key, o._index, conventions)
    35  	return o.Command, err
    36  }
    37  
    38  var _ RavenCommand = &RemoveCompareExchangeValueCommand{}
    39  
    40  type RemoveCompareExchangeValueCommand struct {
    41  	RavenCommandBase
    42  
    43  	_clazz       reflect.Type
    44  	_key         string
    45  	_index       int64
    46  	_conventions *DocumentConventions
    47  
    48  	Result *CompareExchangeResult
    49  }
    50  
    51  func NewRemoveCompareExchangeValueCommand(clazz reflect.Type, key string, index int64, conventions *DocumentConventions) (*RemoveCompareExchangeValueCommand, error) {
    52  	if stringIsEmpty(key) {
    53  		return nil, newIllegalArgumentError("The kye argument must have value")
    54  	}
    55  	cmd := &RemoveCompareExchangeValueCommand{
    56  		RavenCommandBase: NewRavenCommandBase(),
    57  
    58  		_clazz:       clazz,
    59  		_key:         key,
    60  		_index:       index,
    61  		_conventions: conventions,
    62  	}
    63  	cmd.IsReadRequest = true
    64  	return cmd, nil
    65  }
    66  
    67  func (c *RemoveCompareExchangeValueCommand) createRequest(node *ServerNode) (*http.Request, error) {
    68  	url := node.URL + "/databases/" + node.Database + "/cmpxchg?key=" + c._key + "&index=" + i64toa(c._index)
    69  
    70  	return newHttpDelete(url, nil)
    71  }
    72  
    73  func (c *RemoveCompareExchangeValueCommand) setResponse(response []byte, fromCache bool) error {
    74  	var err error
    75  	c.Result, err = parseCompareExchangeResultFromString(c._clazz, response, c._conventions)
    76  	return err
    77  }