On Wed, Sep 2, 2020 at 2:49 PM Alexander Mills <alexander.d.mi...@gmail.com> wrote: > > I have the following code: > > ``` > b := bytes.NewBuffer([]byte("")) > > go func() { > for _, v := range z { > > jsonStr, err := json.Marshal(&v) > > if err != nil { > continue > } > > b.Write([]byte(string(jsonStr) + "\n")) > } > }() > > > fullUrl := fmt.Sprintf("%s/%s", baseUrl, "_bulk") > req, err := http.NewRequest("POST", fullUrl, b)
The request will write whatever is in the buffer and stop there. If you want to stream data, you can use a pipe: rd, wr:=io.Pipe() go func() { defer wr.Close() // Write data to wr }() req, err:=http.NewRequest("POST",URL,rd) > > if err != nil { > log.Fatal(err) > } > > req.Header.Set("Content-Type", "application/json") > > c := http.Client{} > resp, err := c.Do(req) > > > ``` > > is this the correct way to stream the body to the request? > > I put the same code here for ease of reading: > https://gist.github.com/ORESoftware/c76359206fc98659725f17491fb30cca > > -alex > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/9d64d98f-2e7c-408d-99e3-84ee2fbba410n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqpVQyhMo8f40xNbMOtc4eD_YXwBkEraWLvQsSXQzD0PSg%40mail.gmail.com.