Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): improve GO API interface, remove Writable API #145

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

@lidel lidel Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: something like IPFSBackend would be more descriptive, but can be changed later, won't block on this one thing (this interface will most likely get revamp in near future anyway)

// 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/[email protected]/resolver#ErrNoLink
ResolvePath(context.Context, path.Path) (path.Resolved, error)
}

Expand Down
Loading