1
1
package main
2
2
3
3
import (
4
- "errors"
5
4
"flag"
6
5
"io"
7
6
"log"
@@ -21,7 +20,7 @@ func main() {
21
20
portPtr := flag .Int ("p" , 8080 , "port to run this gateway from" )
22
21
flag .Parse ()
23
22
24
- blockService , root , f , err := newBlockServiceFromCAR (* carFilePtr )
23
+ blockService , roots , f , err := newBlockServiceFromCAR (* carFilePtr )
25
24
if err != nil {
26
25
log .Fatal (err )
27
26
}
@@ -36,14 +35,16 @@ func main() {
36
35
37
36
address := "127.0.0.1:" + strconv .Itoa (* portPtr )
38
37
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
+ }
40
41
41
42
if err := http .ListenAndServe (address , handler ); err != nil {
42
43
log .Fatal (err )
43
44
}
44
45
}
45
46
46
- func newBlockServiceFromCAR (filepath string ) (blockservice.BlockService , * cid.Cid , io.Closer , error ) {
47
+ func newBlockServiceFromCAR (filepath string ) (blockservice.BlockService , [] cid.Cid , io.Closer , error ) {
47
48
r , err := os .Open (filepath )
48
49
if err != nil {
49
50
return nil , nil , nil , err
@@ -60,12 +61,8 @@ func newBlockServiceFromCAR(filepath string) (blockservice.BlockService, *cid.Ci
60
61
return nil , nil , nil , err
61
62
}
62
63
63
- if len (roots ) == 0 {
64
- return nil , nil , nil , errors .New ("provided CAR file has no roots" )
65
- }
66
-
67
64
blockService := blockservice .New (bs , offline .Exchange (bs ))
68
- return blockService , & roots [ 0 ] , r , nil
65
+ return blockService , roots , r , nil
69
66
}
70
67
71
68
func newHandler (gw * blocksGateway , port int ) http.Handler {
0 commit comments