Skip to content

Commit 7c44868

Browse files
committed
feat(gateway): improve API interface, remove Writable API
1 parent 7346505 commit 7c44868

13 files changed

+81
-333
lines changed

gateway/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@ headers := map[string][]string{}
1515
gateway.AddAccessControlHeaders(headers)
1616

1717
conf := gateway.Config{
18-
Writable: false,
1918
Headers: headers,
2019
}
2120

2221
// Initialize a NodeAPI interface for both an online and offline versions.
2322
// The offline version should not make any network request for missing content.
2423
ipfs := ...
25-
offlineIPFS := ...
2624

2725
// Create http mux and setup path gateway handler.
2826
mux := http.NewServeMux()
29-
gwHandler := gateway.NewHandler(conf, ipfs, offlineIPFS)
27+
gwHandler := gateway.NewHandler(conf, ipfs)
3028
mux.Handle("/ipfs/", gwHandler)
3129
mux.Handle("/ipns/", gwHandler)
3230

gateway/gateway.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,38 @@ import (
55
"net/http"
66
"sort"
77

8-
coreiface "github.com/ipfs/interface-go-ipfs-core"
9-
path "github.com/ipfs/interface-go-ipfs-core/path"
8+
cid "github.com/ipfs/go-cid"
9+
"github.com/ipfs/go-libipfs/blocks"
10+
"github.com/ipfs/go-libipfs/files"
11+
iface "github.com/ipfs/interface-go-ipfs-core"
12+
options "github.com/ipfs/interface-go-ipfs-core/options"
13+
"github.com/ipfs/interface-go-ipfs-core/path"
1014
)
1115

12-
// Config is the configuration that will be applied when creating a new gateway
13-
// handler.
16+
// Config is the configuration used when creating a new gateway handler.
1417
type Config struct {
15-
Headers map[string][]string
16-
Writable bool
18+
Headers map[string][]string
1719
}
1820

19-
// NodeAPI defines the minimal set of API services required by a gateway handler
20-
type NodeAPI interface {
21-
// Unixfs returns an implementation of Unixfs API
22-
Unixfs() coreiface.UnixfsAPI
21+
// API defines the minimal set of API services required for a gateway handler.
22+
type API interface {
23+
// GetUnixFsNode returns a read-only handle to a file tree referenced by a path.
24+
GetUnixFsNode(context.Context, path.Path) (files.Node, error)
2325

24-
// Block returns an implementation of Block API
25-
Block() coreiface.BlockAPI
26+
// LsUnixFsDir returns the list of links in a directory.
27+
LsUnixFsDir(context.Context, path.Path, ...options.UnixfsLsOption) (<-chan iface.DirEntry, error)
2628

27-
// Dag returns an implementation of Dag API
28-
Dag() coreiface.APIDagService
29+
// GetBlock return a block from a certain CID.
30+
GetBlock(context.Context, cid.Cid) (blocks.Block, error)
2931

30-
// Routing returns an implementation of Routing API.
31-
// Used for returning signed IPNS records, see IPIP-0328
32-
Routing() coreiface.RoutingAPI
32+
// GetIPNSRecord retrieves the best IPNS record for a given CID (libp2p-key)
33+
// from the routing system.
34+
GetIPNSRecord(context.Context, cid.Cid) ([]byte, error)
3335

34-
// ResolvePath resolves the path using Unixfs resolver
36+
// IsCached returns whether or not the path exists locally.
37+
IsCached(context.Context, path.Path) bool
38+
39+
// ResolvePath resolves the path using UnixFS resolver
3540
ResolvePath(context.Context, path.Path) (path.Resolved, error)
3641
}
3742

0 commit comments

Comments
 (0)