shell

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 21 Imported by: 2

README

go-ipfs-api

standard-readme compliant GoDoc Build Status

An unofficial go interface to ipfs's HTTP API

Install

go get -u github.com/ipfs/go-ipfs-api

This will download the source into $GOPATH/src/github.com/ipfs/go-ipfs-api.

Usage

See the godocs for details on available methods. This should match the specs at ipfs/specs; however, there are still some methods which are not accounted for. If you would like to add any of them, see the contribute section below.

Example

Add a file with the contents "hello world!":

package main

import (
	"fmt"
	"strings"
    	"os"

    	shell "github.com/ipfs/go-ipfs-api"
)

func main() {
	// Where your local node is running on localhost:5001
	sh := shell.NewShell("localhost:5001")
	cid, err := sh.Add(strings.NewReader("hello world!"))
	if err != nil {
        fmt.Fprintf(os.Stderr, "error: %s", err)
        os.Exit(1)
	}
    fmt.Printf("added %s", cid)
}

For a more complete example, please see: https://github.com/ipfs/go-ipfs-api/blob/master/tests/main.go

Contribute

Contributions are welcome! Please check out the issues.

Want to hack on IPFS?

License

MIT

Documentation

Overview

package shell implements a remote API interface for a running ipfs daemon

Index

Constants

View Source
const (
	DefaultPathName = ".ipfs"
	DefaultPathRoot = "~/" + DefaultPathName
	DefaultApiFile  = "api"
	EnvDir          = "IPFS_PATH"
)
View Source
const (
	TRaw = iota
	TDirectory
	TFile
	TMetadata
	TSymlink
)
View Source
const (
	DirectPin    = "direct"
	RecursivePin = "recursive"
	IndirectPin  = "indirect"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOpts added in v1.4.0

type AddOpts = func(*RequestBuilder) error

func OnlyHash added in v1.4.0

func OnlyHash(enabled bool) AddOpts

func Pin added in v1.4.0

func Pin(enabled bool) AddOpts

func Progress added in v1.4.0

func Progress(enabled bool) AddOpts

func RawLeaves added in v1.4.0

func RawLeaves(enabled bool) AddOpts

type Error

type Error struct {
	Command string
	Message string
	Code    int
}

func (*Error) Error

func (e *Error) Error() string

type IdOutput

type IdOutput struct {
	ID              string
	PublicKey       string
	Addresses       []string
	AgentVersion    string
	ProtocolVersion string
}

type IpfsObject

type IpfsObject struct {
	Links []ObjectLink
	Data  string
}
type LsLink struct {
	Hash string
	Name string
	Size uint64
	Type int
}

type LsObject

type LsObject struct {
	Links []*LsLink
	LsLink
}

type Message added in v1.4.0

type Message struct {
	From     string
	Data     []byte
	Seqno    []byte
	TopicIDs []string
}

Message is a pubsub message.

type ObjectLink struct {
	Name, Hash string
	Size       uint64
}

type ObjectStats added in v1.1.1

type ObjectStats struct {
	Hash           string
	BlockSize      int
	CumulativeSize int
	DataSize       int
	LinksSize      int
	NumLinks       int
}

type PeerInfo

type PeerInfo struct {
	Addrs []string
	ID    string
}

type PeersList added in v1.3.3

type PeersList struct {
	Peers []string
}

type PinInfo added in v1.1.0

type PinInfo struct {
	Type string
}

type PubSubSubscription added in v1.1.0

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

PubSubSubscription allow you to receive pubsub records that where published on the network.

func (*PubSubSubscription) Cancel added in v1.1.0

func (s *PubSubSubscription) Cancel() error

Cancel cancels the given subscription.

func (*PubSubSubscription) Next added in v1.1.0

func (s *PubSubSubscription) Next() (*Message, error)

Next waits for the next record and returns that.

type PublishResponse added in v1.3.0

type PublishResponse struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Request

type Request struct {
	ApiBase string
	Command string
	Args    []string
	Opts    map[string]string
	Body    io.Reader
	Headers map[string]string
}

func NewRequest

func NewRequest(ctx context.Context, url, command string, args ...string) *Request

func (*Request) Send

func (r *Request) Send(c *http.Client) (*Response, error)

type RequestBuilder added in v1.3.3

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

RequestBuilder is an IPFS commands request builder.

func (*RequestBuilder) Arguments added in v1.3.3

func (r *RequestBuilder) Arguments(args ...string) *RequestBuilder

Arguments adds the arguments to the args.

func (*RequestBuilder) Body added in v1.3.3

func (r *RequestBuilder) Body(body io.Reader) *RequestBuilder

Body sets the request body to the given reader.

func (*RequestBuilder) BodyBytes added in v1.3.3

func (r *RequestBuilder) BodyBytes(body []byte) *RequestBuilder

BodyBytes sets the request body to the given buffer.

func (*RequestBuilder) BodyString added in v1.3.3

func (r *RequestBuilder) BodyString(body string) *RequestBuilder

BodyString sets the request body to the given string.

func (*RequestBuilder) Exec added in v1.3.3

func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error

Exec sends the request a request and decodes the response.

func (*RequestBuilder) Header added in v1.3.3

func (r *RequestBuilder) Header(name, value string) *RequestBuilder

Header sets the given header.

func (*RequestBuilder) Option added in v1.3.3

func (r *RequestBuilder) Option(key string, value interface{}) *RequestBuilder

Option sets the given option.

func (*RequestBuilder) Send added in v1.3.3

func (r *RequestBuilder) Send(ctx context.Context) (*Response, error)

Send sends the request and return the response.

type Response

type Response struct {
	Output io.ReadCloser
	Error  *Error
}

func (*Response) Close

func (r *Response) Close() error

func (*Response) Decode added in v1.3.3

func (r *Response) Decode(dec interface{}) error

type Shell

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

func NewLocalShell added in v1.1.1

func NewLocalShell() *Shell

func NewShell

func NewShell(url string) *Shell

func NewShellWithClient added in v1.1.0

func NewShellWithClient(url string, c *gohttp.Client) *Shell

func (*Shell) Add

func (s *Shell) Add(r io.Reader, options ...AddOpts) (string, error)

func (*Shell) AddDir

func (s *Shell) AddDir(dir string) (string, error)

AddDir adds a directory recursively with all of the files under it

func (s *Shell) AddLink(target string) (string, error)

func (*Shell) AddNoPin added in v1.1.0

func (s *Shell) AddNoPin(r io.Reader) (string, error)

AddNoPin adds a file to ipfs without pinning it Deprecated: Use Add() with option functions instead

func (*Shell) AddWithOpts added in v1.2.0

func (s *Shell) AddWithOpts(r io.Reader, pin bool, rawLeaves bool) (string, error)

AddWithOpts adds a file to ipfs with some additional options Deprecated: Use Add() with option functions instead

func (*Shell) BlockGet

func (s *Shell) BlockGet(path string) ([]byte, error)

func (*Shell) BlockPut

func (s *Shell) BlockPut(block []byte, format, mhtype string, mhlen int) (string, error)

func (*Shell) BlockStat

func (s *Shell) BlockStat(path string) (string, int, error)

func (*Shell) BootstrapAdd added in v1.2.7

func (s *Shell) BootstrapAdd(peers []string) ([]string, error)

func (*Shell) BootstrapAddDefault added in v1.2.7

func (s *Shell) BootstrapAddDefault() ([]string, error)

func (*Shell) BootstrapRmAll added in v1.2.7

func (s *Shell) BootstrapRmAll() ([]string, error)

func (*Shell) Cat

func (s *Shell) Cat(path string) (io.ReadCloser, error)

Cat the content at the given path. Callers need to drain and close the returned reader after usage.

func (*Shell) DagGet added in v1.1.0

func (s *Shell) DagGet(ref string, out interface{}) error

func (*Shell) DagPut added in v1.1.0

func (s *Shell) DagPut(data interface{}, ienc, kind string) (string, error)

func (*Shell) DagPutWithOpts added in v1.4.0

func (s *Shell) DagPutWithOpts(data interface{}, opts ...options.DagPutOption) (string, error)

func (*Shell) FileList

func (s *Shell) FileList(path string) (*UnixLsObject, error)

FileList entries at the given path using the UnixFS commands

func (*Shell) FindPeer

func (s *Shell) FindPeer(peer string) (*PeerInfo, error)

func (*Shell) Get

func (s *Shell) Get(hash, outdir string) error

func (*Shell) ID

func (s *Shell) ID(peer ...string) (*IdOutput, error)

ID gets information about a given peer. Arguments:

peer: peer.ID of the node to look up. If no peer is specified,

return information about the local peer.

func (*Shell) IsUp

func (s *Shell) IsUp() bool

func (*Shell) List

func (s *Shell) List(path string) ([]*LsLink, error)

List entries at the given path

func (*Shell) NewObject

func (s *Shell) NewObject(template string) (string, error)

func (*Shell) ObjectGet

func (s *Shell) ObjectGet(path string) (*IpfsObject, error)

func (*Shell) ObjectPut

func (s *Shell) ObjectPut(obj *IpfsObject) (string, error)

func (*Shell) ObjectStat added in v1.1.1

func (s *Shell) ObjectStat(key string) (*ObjectStats, error)

ObjectStat gets stats for the DAG object named by key. It returns the stats of the requested Object or an error.

func (*Shell) Patch

func (s *Shell) Patch(root, action string, args ...string) (string, error)

func (*Shell) PatchData

func (s *Shell) PatchData(root string, set bool, data interface{}) (string, error)
func (s *Shell) PatchLink(root, path, childhash string, create bool) (string, error)

func (*Shell) Pin

func (s *Shell) Pin(path string) error

Pin the given path

func (*Shell) Pins added in v1.1.0

func (s *Shell) Pins() (map[string]PinInfo, error)

Pins returns a map of the pin hashes to their info (currently just the pin type, one of DirectPin, RecursivePin, or IndirectPin. A map is returned instead of a slice because it is easier to do existence lookup by map key than unordered array searching. The map is likely to be more useful to a client than a flat list.

func (*Shell) PubSubPublish added in v1.1.0

func (s *Shell) PubSubPublish(topic, data string) (err error)

func (*Shell) PubSubSubscribe added in v1.1.0

func (s *Shell) PubSubSubscribe(topic string) (*PubSubSubscription, error)

func (*Shell) Publish

func (s *Shell) Publish(node string, value string) error

Publish updates a mutable name to point to a given value

func (*Shell) PublishWithDetails added in v1.3.0

func (s *Shell) PublishWithDetails(contentHash, key string, lifetime, ttl time.Duration, resolve bool) (*PublishResponse, error)

PublishWithDetails is used for fine grained control over record publishing

func (*Shell) Refs

func (s *Shell) Refs(hash string, recursive bool) (<-chan string, error)

func (*Shell) Request added in v1.3.3

func (s *Shell) Request(command string, args ...string) *RequestBuilder

func (*Shell) Resolve

func (s *Shell) Resolve(id string) (string, error)

Resolve gets resolves the string provided to an /ipns/[name]. If asked to resolve an empty string, resolve instead resolves the node's own /ipns value.

func (*Shell) ResolvePath

func (s *Shell) ResolvePath(path string) (string, error)

func (*Shell) SetTimeout

func (s *Shell) SetTimeout(d time.Duration)

func (*Shell) StatsBW added in v1.3.3

func (s *Shell) StatsBW(ctx context.Context) (*Stats, error)

ObjectStat gets stats for the DAG object named by key. It returns the stats of the requested Object or an error.

func (*Shell) SwarmConnect added in v1.3.3

func (s *Shell) SwarmConnect(ctx context.Context, addr ...string) error

SwarmConnect opens a swarm connection to a specific address.

func (*Shell) SwarmPeers added in v1.3.3

func (s *Shell) SwarmPeers(ctx context.Context) (*SwarmConnInfos, error)

SwarmPeers gets all the swarm peers

func (*Shell) Unpin

func (s *Shell) Unpin(path string) error

Unpin the given path

func (*Shell) Version

func (s *Shell) Version() (string, string, error)

returns ipfs version and commit sha

type Stats added in v1.4.0

type Stats struct {
	TotalIn  int64
	TotalOut int64
	RateIn   float64
	RateOut  float64
}

type SwarmConnInfo added in v1.3.3

type SwarmConnInfo struct {
	Addr    string
	Peer    string
	Latency string
	Muxer   string
	Streams []SwarmStreamInfo
}

type SwarmConnInfos added in v1.3.3

type SwarmConnInfos struct {
	Peers []SwarmConnInfo
}

type SwarmStreamInfo added in v1.3.3

type SwarmStreamInfo struct {
	Protocol string
}
type UnixLsLink struct {
	Hash string
	Name string
	Size uint64
	Type string
}

type UnixLsObject

type UnixLsObject struct {
	Hash  string
	Size  uint64
	Type  string
	Links []*UnixLsLink
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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