gw3

package module
v0.0.0-...-12a24ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 15 Imported by: 0

README

gw3-sdk-go

This repository contains the Golang SDK for Gateway3, an IPFS decentralized gateway. The Gateway3 SDK provides a simple and easy-to-use interface to interact with IPFS, enabling developers to build scalable and distributed applications.

Features

  • Seamless integration with IPFS network
  • Store and retrieve files on the decentralized web
  • Simplified and intuitive API
  • Built-in support for pinning
  • Secure and private data handling
  • Lightweight and highly performant

Getting Started

Prerequisites
  • Golang version 1.19 or higher
Obtain Access Key and Access Secret

To use the Gateway3 SDK, you need to obtain an access key and access secret. You can get these by logging in to the Photon Storage website at https://www.gw3.io/.

Installation

To install the Gateway3 SDK, use the following command:

go get -u github.com/photon-storage/gw3-sdk-go
Usage

Import the Gateway3 SDK in your Golang project:

import "github.com/photon-storage/gw3-sdk-go"

Here's a simple example demonstrating the usage of the Gateway3 IPFS Gateway SDK:

package main

import (
	"fmt"

	"github.com/photon-storage/gw3-sdk-go"
)

func main() {
	key := "YOUR-ACCESS-KEY"
	secret := "YOUR-ACCESS-SECRET"
	client, err := gw3.NewClient(key, secret)
	if err != nil {
		panic(err)
	}

	data := "EThe Times 03/Jan/2009 Chancellor on brink of second bailout for banks"

	// Post the data to the IPFS network, receiving a CID as a result
	cid, err := client.Post([]byte(data))
	if err != nil {
		panic(err)
	}
	fmt.Println("Data posted to IPFS network, CID is: ", cid)

	// Request the gateway to pin the CID data, ensuring its persistence
	if err := client.Pin(cid); err != nil {
		panic(err)
	}
	fmt.Println("CID data is pinned by the Gateway3")

	// Retrieve the data from the IPFS network using the CID
	got, err := client.Get(cid)
	if err != nil {
		panic(err)
	}
	fmt.Println("Data retrieved from IPFS network: ", string(got))
}

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Documentation

Index

Constants

View Source
const (
	EmptyDAGRoot = "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Gateway3 client for interacting with the Gateway3.

func NewClient

func NewClient(accessKey, accessSecret string) (*Client, error)

NewClient creates a new Gateway3 client with the provided access key and access secret.

func (*Client) AuthDAGAdd

func (c *Client) AuthDAGAdd(root, filePath string, size int) (string, error)

AuthDAGAdd requests Gateway3 for an authorized redirect URL for subsequently adding a new CID and path to the existing dag.

func (*Client) AuthDAGImport

func (c *Client) AuthDAGImport(size int) (string, error)

AuthDAGImport requests Gateway3 for an authorized redirect URL for uploading a CAR file.

func (*Client) AuthDAGRemove

func (c *Client) AuthDAGRemove(root, filePath string) (string, error)

AuthDAGRemove requests Gateway3 for an authorized redirect URL for subsequently removing a path from the existing dag, generating a new dag root.

func (*Client) AuthPost

func (c *Client) AuthPost(size int) (string, error)

AuthPost gets the authorized URL from the Gateway3.

func (*Client) CreateIPNS

func (c *Client) CreateIPNS(value string) (string, error)

CreateIPNS creates a new IPNS record and binds it to the given CID. This function should only be used for creating a new record. To update an existing IPNS record, use the UpdateIPNS interface.

func (*Client) DAGAdd

func (c *Client) DAGAdd(root, path string, data []byte) (string, error)

DAGAdd adds a new CID and path to the existing dag, generating a new dag root.

func (*Client) DAGImport

func (c *Client) DAGImport(src any) (string, error)

DAGImport imports the given src input as a CAR format and returns its root CID. The `src` can be a path to a directory, a byte array or a io.Reader.

func (*Client) DAGRemove

func (c *Client) DAGRemove(root, path string) (string, error)

DAGRemove removes a path from the existing dag, generating a new dag root.

func (*Client) Get

func (c *Client) Get(cid string) ([]byte, error)

Get retrieves data from the Gateway3 for the given CID.

func (*Client) GetIPNS

func (c *Client) GetIPNS(name string) ([]byte, error)

GetIPNS retrieves data from the IPFS network using the given IPNS.

func (*Client) ImportIPNS

func (c *Client) ImportIPNS(body *ImportIPNSReq) error

ImportIPNS imports an IPNS record using a user-side generated private key.

func (*Client) Pin

func (c *Client) Pin(cid string) error

Pin requests Gateway3 to pin the given CID.

func (*Client) Post

func (c *Client) Post(data []byte) (string, error)

Post uploads the given data to Gateway3 and returns the corresponding CID.

func (*Client) Unpin

func (c *Client) Unpin(cid string) error

Unpin requests Gateway3 to unpin the given CID.

func (*Client) UpdateIPNS

func (c *Client) UpdateIPNS(name, value string) error

UpdateIPNS updates the value for the IPNS record specified by the given name.

type ImportIPNSReq

type ImportIPNSReq struct {
	Name      string `json:"name"`
	Value     string `json:"value"`
	SecretKey string `json:"secret_key"`
	Format    string `json:"format"`
	Seq       uint64 `json:"seq"`
}

ImportIPNSReq defines the request payload for importing an IPNS record

Directories

Path Synopsis
dag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL