thanks that looks correct to me On Wednesday, September 2, 2020 at 2:16:30 PM UTC-7 bbse...@gmail.com wrote:
> On Wed, Sep 2, 2020 at 2:49 PM Alexander Mills > <alexande...@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...@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/45ad1c72-63be-4936-9845-66318dd25ef5n%40googlegroups.com.