Skip to content

Commit ba3b5c0

Browse files
authored
Merge pull request apache#1 from zeroshade/http-examples/go
2 parents ecb541a + 8abdc81 commit ba3b5c0

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

http/examples/get/client.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"time"
7+
8+
"github.com/apache/arrow/go/v15/arrow"
9+
"github.com/apache/arrow/go/v15/arrow/ipc"
10+
"github.com/apache/arrow/go/v15/arrow/memory"
11+
)
12+
13+
func main() {
14+
start := time.Now()
15+
resp, err := http.Get("http://localhost:8000")
16+
if err != nil {
17+
panic(err)
18+
}
19+
20+
if resp.StatusCode != http.StatusOK {
21+
panic(fmt.Errorf("got non-200 status: %d", resp.StatusCode))
22+
}
23+
defer resp.Body.Close()
24+
25+
rdr, err := ipc.NewReader(resp.Body, ipc.WithAllocator(memory.DefaultAllocator))
26+
if err != nil {
27+
panic(err)
28+
}
29+
defer rdr.Release()
30+
31+
batches := make([]arrow.Record, 0)
32+
defer func() {
33+
for _, b := range batches {
34+
b.Release()
35+
}
36+
}()
37+
38+
for rdr.Next() {
39+
rec := rdr.Record()
40+
rec.Retain()
41+
batches = append(batches, rec)
42+
}
43+
44+
if rdr.Err() != nil {
45+
panic(rdr.Err())
46+
}
47+
48+
execTime := time.Since(start)
49+
50+
fmt.Println(resp.ContentLength, " bytes recieved")
51+
fmt.Println(len(batches), " record batches received")
52+
fmt.Println(execTime.Seconds(), " seconds elapsed")
53+
}

0 commit comments

Comments
 (0)