# README
go-w3s-client
A client to the Web3.Storage API.
Demo: https://youtu.be/FLsQZ_ogeOg
Install
go get github.com/web3-storage/go-w3s-client
Usage
package main
import (
"io/fs"
"os"
"github.com/web3-storage/go-w3s-client"
)
func main() {
c, _ := w3s.NewClient(w3s.WithToken("<AUTH_TOKEN>"))
f, _ := os.Open("images/pinpie.jpg")
// OR add a whole directory:
//
// f, _ := os.Open("images")
//
// OR create your own directory:
//
// img0, _ := os.Open("aliens.jpg")
// img1, _ := os.Open("donotresist.jpg")
// f := w3fs.NewDir("images", []fs.File{img0, img1})
// Write a file/directory
cid, _ := c.Put(context.Background(), f)
fmt.Printf("https://%v.ipfs.dweb.link\n", cid)
// Retrieve a file/directory
res, _ := c.Get(context.Background(), cid)
// res is a http.Response with an extra method for reading IPFS UnixFS files!
f, fsys, _ := res.Files()
// List directory entries
if d, ok := f.(fs.ReadDirFile); ok {
ents, _ := d.ReadDir(0)
for _, ent := range ents {
fmt.Println(ent.Name())
}
}
// Walk whole directory contents (including nested directories)
fs.WalkDir(fsys, "/", func(path string, d fs.DirEntry, err error) error {
info, _ := d.Info()
fmt.Printf("%s (%d bytes)\n", path, info.Size())
return err
})
// Open a file in a directory
img, _ := fsys.Open("pinpie.jpg")
// img.Stat()
// img.Read(...)
// img.Close()
}
See example for more.
API
Contribute
Feel free to dive in! Open an issue or submit PRs.
License
Dual-licensed under MIT + Apache 2.0
# Functions
NewClient creates a new web3.storage API client.
WithBefore sets the time that items in the list were uploaded before.
WithDatastore sets the underlying datastore to use when reading or writing DAG block data.
WithDirname sets the root directory path, for use when the provided file is a directory and does NOT implement fs.ReadDirFile.
WithEndpoint sets the URL of the root API when making requests (default https://api.web3.storage).
WithFs sets the file system interface for use with file operations.
WithHTTPClient sets the HTTP client to use when making requests which allows timeouts and redirect behaviour to be configured.
WithMaxResults sets the maximum number of results that will be available from the iterator.
WithPinMeta adds metadata about pinned data.
WithPinName sets the name to use for the pinned data.
WithPinOrigin adds a multiaddr known to provide the data.
WithToken sets the auth token to use in the Authorization header when making requests to the API.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Status is IPFS pin and Filecoin deal status for a given CID.
No description provided by the author
# Interfaces
Client is a HTTP API client to the web3.storage service.
# Type aliases
No description provided by the author
ListOption is an option configuring a call to List.
Option is an option configuring a web3.storage client.
PinOption is an option configuring a call to Pin.
No description provided by the author
PutOption is an option configuring a call to Put.