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

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  var (
     8  	_ RavenCommand = &StreamCommand{}
     9  )
    10  
    11  type StreamCommand struct {
    12  	RavenCommandBase
    13  
    14  	_url string
    15  
    16  	Result *StreamResultResponse
    17  }
    18  
    19  func NewStreamCommand(url string) *StreamCommand {
    20  	// TODO: validate url
    21  	cmd := &StreamCommand{
    22  		RavenCommandBase: NewRavenCommandBase(),
    23  
    24  		_url: url,
    25  	}
    26  	cmd.IsReadRequest = true
    27  	return cmd
    28  }
    29  
    30  func (c *StreamCommand) createRequest(node *ServerNode) (*http.Request, error) {
    31  	url := node.URL + "/databases/" + node.Database + "/" + c._url
    32  	return newHttpGet(url)
    33  }
    34  
    35  func (c *StreamCommand) processResponse(cache *httpCache, response *http.Response, url string) (responseDisposeHandling, error) {
    36  
    37  	// TODO: return an error if response.Body is nil
    38  	streamResponse := &StreamResultResponse{
    39  		Response: response,
    40  		Stream:   response.Body,
    41  	}
    42  	c.Result = streamResponse
    43  
    44  	return responseDisposeHandlingManually, nil
    45  }