Skip to content

Commit 691d1b9

Browse files
committed
fix: print all car roots
1 parent 187bead commit 691d1b9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

examples/gateway-car/main.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"errors"
54
"flag"
65
"io"
76
"log"
@@ -21,7 +20,7 @@ func main() {
2120
portPtr := flag.Int("p", 8080, "port to run this gateway from")
2221
flag.Parse()
2322

24-
blockService, root, f, err := newBlockServiceFromCAR(*carFilePtr)
23+
blockService, roots, f, err := newBlockServiceFromCAR(*carFilePtr)
2524
if err != nil {
2625
log.Fatal(err)
2726
}
@@ -36,14 +35,16 @@ func main() {
3635

3736
address := "127.0.0.1:" + strconv.Itoa(*portPtr)
3837
log.Printf("Listening on http://%s", address)
39-
log.Printf("Hosting CAR root at http://%s/ipfs/%s", address, root.String())
38+
for _, cid := range roots {
39+
log.Printf("Hosting CAR root at http://%s/ipfs/%s", address, cid.String())
40+
}
4041

4142
if err := http.ListenAndServe(address, handler); err != nil {
4243
log.Fatal(err)
4344
}
4445
}
4546

46-
func newBlockServiceFromCAR(filepath string) (blockservice.BlockService, *cid.Cid, io.Closer, error) {
47+
func newBlockServiceFromCAR(filepath string) (blockservice.BlockService, []cid.Cid, io.Closer, error) {
4748
r, err := os.Open(filepath)
4849
if err != nil {
4950
return nil, nil, nil, err
@@ -60,12 +61,8 @@ func newBlockServiceFromCAR(filepath string) (blockservice.BlockService, *cid.Ci
6061
return nil, nil, nil, err
6162
}
6263

63-
if len(roots) == 0 {
64-
return nil, nil, nil, errors.New("provided CAR file has no roots")
65-
}
66-
6764
blockService := blockservice.New(bs, offline.Exchange(bs))
68-
return blockService, &roots[0], r, nil
65+
return blockService, roots, r, nil
6966
}
7067

7168
func newHandler(gw *blocksGateway, port int) http.Handler {

0 commit comments

Comments
 (0)