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

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  type GetOperationStateOperation struct {
     8  	id int64
     9  }
    10  
    11  func (o *GetOperationStateOperation) GetCommand(conventions *DocumentConventions) *GetOperationStateCommand {
    12  	return NewGetOperationStateCommand(getDefaultConventions(), o.id)
    13  }
    14  
    15  type GetOperationStateCommand struct {
    16  	RavenCommandBase
    17  
    18  	conventions *DocumentConventions
    19  	id          int64
    20  
    21  	Result map[string]interface{}
    22  }
    23  
    24  func NewGetOperationStateCommand(conventions *DocumentConventions, id int64) *GetOperationStateCommand {
    25  	cmd := &GetOperationStateCommand{
    26  		RavenCommandBase: NewRavenCommandBase(),
    27  
    28  		conventions: conventions,
    29  		id:          id,
    30  	}
    31  	cmd.IsReadRequest = true
    32  
    33  	return cmd
    34  }
    35  
    36  func (c *GetOperationStateCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
    37  	url := node.URL + "/databases/" + node.Database + "/operations/state?id=" + i64toa(c.id)
    38  	return newHttpGet(url)
    39  }
    40  
    41  func (c *GetOperationStateCommand) SetResponse(response []byte, fromCache bool) error {
    42  	if len(response) == 0 {
    43  		return nil
    44  	}
    45  
    46  	return jsonUnmarshal(response, &c.Result)
    47  }