github.com/altipla-consulting/ravendb-go-client@v0.1.3/query_stream_command.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var ( 8 _ RavenCommand = &QueryStreamCommand{} 9 ) 10 11 type QueryStreamCommand struct { 12 RavenCommandBase 13 14 _conventions *DocumentConventions 15 _indexQuery *IndexQuery 16 17 Result *StreamResultResponse 18 } 19 20 func NewQueryStreamCommand(conventions *DocumentConventions, indexQuery *IndexQuery) *QueryStreamCommand { 21 panicIf(indexQuery == nil, "IndexQuery cannot be null") 22 // TODO: validate convention 23 cmd := &QueryStreamCommand{ 24 RavenCommandBase: NewRavenCommandBase(), 25 26 _conventions: conventions, 27 _indexQuery: indexQuery, 28 } 29 cmd.IsReadRequest = true 30 return cmd 31 } 32 33 func (c *QueryStreamCommand) createRequest(node *ServerNode) (*http.Request, error) { 34 url := node.URL + "/databases/" + node.Database + "/streams/queries" 35 36 m := jsonExtensionsWriteIndexQuery(c._conventions, c._indexQuery) 37 d, err := jsonMarshal(m) 38 if err != nil { 39 return nil, err 40 } 41 return newHttpPost(url, d) 42 } 43 44 func (c *QueryStreamCommand) processResponse(cache *httpCache, response *http.Response, url string) (responseDisposeHandling, error) { 45 46 // TODO: return an error if response.Body is nil 47 streamResponse := &StreamResultResponse{ 48 Response: response, 49 Stream: response.Body, 50 } 51 c.Result = streamResponse 52 53 return responseDisposeHandlingManually, nil 54 }