Skip to content

Commit

Permalink
Merge pull request #145 from ipfs/refactor/decouple-read-write-gateway
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
lidel authored Feb 2, 2023
2 parents 7346505 + c7cc8b8 commit 6399b73
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 341 deletions.
4 changes: 1 addition & 3 deletions gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ headers := map[string][]string{}
gateway.AddAccessControlHeaders(headers)

conf := gateway.Config{
Writable: false,
Headers: headers,
}

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

// Create http mux and setup path gateway handler.
mux := http.NewServeMux()
gwHandler := gateway.NewHandler(conf, ipfs, offlineIPFS)
gwHandler := gateway.NewHandler(conf, ipfs)
mux.Handle("/ipfs/", gwHandler)
mux.Handle("/ipns/", gwHandler)

Expand Down
42 changes: 24 additions & 18 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@ import (
"net/http"
"sort"

coreiface "github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-libipfs/blocks"
"github.com/ipfs/go-libipfs/files"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
)

// Config is the configuration that will be applied when creating a new gateway
// handler.
// Config is the configuration used when creating a new gateway handler.
type Config struct {
Headers map[string][]string
Writable bool
Headers map[string][]string
}

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

// Block returns an implementation of Block API
Block() coreiface.BlockAPI
// LsUnixFsDir returns the list of links in a directory.
LsUnixFsDir(context.Context, path.Resolved) (<-chan iface.DirEntry, error)

// Dag returns an implementation of Dag API
Dag() coreiface.APIDagService
// GetBlock return a block from a certain CID.
GetBlock(context.Context, cid.Cid) (blocks.Block, error)

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

// ResolvePath resolves the path using Unixfs resolver
// IsCached returns whether or not the path exists locally.
IsCached(context.Context, path.Path) bool

// ResolvePath resolves the path using UnixFS resolver. If the path does not
// exist due to a missing link, it should return an error of type:
// https://pkg.go.dev/github.com/ipfs/go-path@v0.3.0/resolver#ErrNoLink
ResolvePath(context.Context, path.Path) (path.Resolved, error)
}

Expand Down
Loading

0 comments on commit 6399b73

Please sign in to comment.