Documentation
¶
Index ¶
- func NewClient(rpcAddr string) (*rpc.HttpApi, error)
- type Client
- type ClientImpl
- func (c *ClientImpl) Add(ctx context.Context, fileName, filePath string) (string, string, error)
- func (c *ClientImpl) DeleteFile(ctx context.Context, objectPath string) error
- func (c *ClientImpl) DisplayFileContent(ctx context.Context, filePath string) (string, error)
- func (c *ClientImpl) DownloadDir(ctx context.Context, cid string, outputPath string) error
- func (c *ClientImpl) DownloadFile(ctx context.Context, cid string) ([]byte, error)
- func (c *ClientImpl) ListConnectedNodes(ctx context.Context) ([]Node, error)
- func (c *ClientImpl) ListDir(ctx context.Context, dirPath string) ([]DirFileDetail, error)
- func (c *ClientImpl) ListPins(ctx context.Context) (any, error)
- func (c *ClientImpl) NodeInfo(ctx context.Context, peerID string) (NodeInfo, error)
- func (c *ClientImpl) PinObject(ctx context.Context, name, objectPath string) error
- func (c *ClientImpl) Ping(ctx context.Context, peerID string) ([]PingInfo, error)
- type DirFileDetail
- type Node
- type NodeInfo
- type PingInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface {
NodeInfo(ctx context.Context, peerID string) (NodeInfo, error)
Ping(ctx context.Context, peerID string) ([]PingInfo, error)
Add(ctx context.Context, fileName, filePath string) (string, string, error)
DownloadFile(ctx context.Context, cid string) ([]byte, error)
ListConnectedNodes(ctx context.Context) ([]Node, error)
ListPins(ctx context.Context) (any, error)
PinObject(ctx context.Context, name, objectPath string) error
DeleteFile(ctx context.Context, objectPath string) error
DisplayFileContent(ctx context.Context, filePath string) (string, error)
DownloadDir(ctx context.Context, cid string, outputPath string) error
ListDir(ctx context.Context, dirPath string) ([]DirFileDetail, error)
}
Client is an interface that provides methods for interacting with an IPFS node.
func NewClientImpl ¶
NewClientImpl creates a new IPFS client implementation.
type ClientImpl ¶
type ClientImpl struct {
// contains filtered or unexported fields
}
ClientImpl is the implementation of the IPFS client.
func (*ClientImpl) Add ¶
Add adds a file or directory to IPFS and returns the immutable path and root CID of the added object.
func (*ClientImpl) DeleteFile ¶
func (c *ClientImpl) DeleteFile(ctx context.Context, objectPath string) error
DeleteFile unpins the IPFS object at the given path and then performs a garbage collection to remove the unpinned object.
func (*ClientImpl) DisplayFileContent ¶
DisplayFileContent returns the contents of the file at the given path as a string. If the path is empty, it returns an error.
func (*ClientImpl) DownloadDir ¶
DownloadDir retrieves the IPFS object (directory) at the given CID and writes it to the specified output path.
func (*ClientImpl) DownloadFile ¶
DownloadFile downloads the IPFS object with the given CID and returns its contents as a byte slice. If the object is not a file, an error is returned.
func (*ClientImpl) ListConnectedNodes ¶
func (c *ClientImpl) ListConnectedNodes(ctx context.Context) ([]Node, error)
ListConnectedNodes returns a list of all the nodes that the current IPFS node is connected to. For each node, the function returns the node ID, address, connection direction, and latency.
func (*ClientImpl) ListDir ¶
func (c *ClientImpl) ListDir(ctx context.Context, dirPath string) ([]DirFileDetail, error)
ListDir returns a list of all the files and directories in the specified directory path. For each file/directory, the function returns the name, CID, size, and type.
func (*ClientImpl) ListPins ¶
func (c *ClientImpl) ListPins(ctx context.Context) (any, error)
ListPins returns a list of all the IPFS objects that are currently pinned.
func (*ClientImpl) NodeInfo ¶
NodeInfo returns information about the local IPFS node, including its addresses, agent version, ID, supported protocols, and public key.
type DirFileDetail ¶
type DirFileDetail struct {
Name string `json:"name"` // the name of the file or directory.
Cid cid.Cid `json:"cid"` // the CID of the file or directory.
Size uint64 `json:"size"` // the size of the file in bytes (or the size of the symlink).
Type iface.FileType `json:"type"` // the type of the file.
}
DirFileDetail represents details about a file or directory in IPFS.
type Node ¶
type Node struct {
ID string `json:"id"` // the ID of the node.
Address string `json:"address"` // the address of the node.
Direction string `json:"direction"` // the direction of the connection (inbound or outbound).
Latency int64 `json:"latency"` // the latency of the connection to the node.
}
Node represents an IPFS node.
type NodeInfo ¶
type NodeInfo struct {
Addresses []string `json:"addresses"` // the addresses of the node.
AgentVersion string `json:"AgentVersion"` // the version of the IPFS agent.
ID string `json:"id"` // the ID of the node.
Protocols []string `json:"protocols"` // the protocols supported by the node.
PublicKey string `json:"PublicKey"` // the public key of the node.
}
NodeInfo contains information about an IPFS node. TODO: look into 'AgentVersion' and 'PublicKey' fields