Coder Social home page Coder Social logo

go-ipfs-api's Introduction

⚠️ This package is no longer being maintained ⚠️

Please use kubo/client/rpc instead. In rare case the new library does not offer a feature this one does, fill issue in Kubo, or better, submit a PR that adds it to kubo/client/rpc.

For more details about the decision, see ipfs/kubo#9124.

go-ipfs-api

standard-readme compliant GoDoc Build Status

The go interface to ipfs's HTTP API

Install

go install github.com/ipfs/go-ipfs-api@latest

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 (Core API); 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. See also the HTTP API.

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

go-ipfs-api's People

Contributors

2color avatar adamgall avatar aschmahmann avatar cryptix avatar dependabot-preview[bot] avatar djdv avatar galargh avatar gfanton avatar guseggert avatar hacdias avatar hsanjuan avatar jbenet avatar keks avatar kubuxu avatar listenaddress avatar magik6k avatar michaelmure avatar optman avatar pengisgood avatar polamarasettyrohitha avatar postables avatar richardlitt avatar ridewindx avatar scroot avatar stebalien avatar varunram avatar web-flow avatar web3-bot avatar whyrusleeping avatar wking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ipfs-api's Issues

go-ipfs-api cant add file via http

First request to IPFS using curl works
curl -i -H "Content-Type: multipart/form-data; boundary=CUSTOM" -d $'--CUSTOM\r\nContent-Type: multipart/octet-stream\r\nContent-Disposition: file; filename="test"\r\n\r\nHello World!\n--CUSTOM--' "http://1.1.1.1:5001/api/v0/add?encoding=json&stream-channels=true"

Send

POST /api/v0/add?encoding=json&stream-channels=true HTTP/1.1
Host: 1.1.1.1:5001
User-Agent: curl/7.43.0
Accept: */*
Content-Type: multipart/form-data; boundary=CUSTOM
Content-Length: 117

--CUSTOM
Content-Type: multipart/octet-stream
Content-Disposition: file; filename="test"

Hello World!
--CUSTOM--

Result

{"Name":"test","Hash":"QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG"}

Sending request using go-ipfs-api

POST /api/v0/add?encoding=json&stream-channels=true HTTP/1.1
Host: 1.1.1.1:5001
User-Agent: Go-http-client/1.1
Transfer-Encoding: chunked
Content-Disposition: form-data: name="files"
Content-Type: multipart/form-data; boundary=04f67da35c831a08306078cd32c7bac8f906018e58c2bdbe56d05323a1b9
Accept-Encoding: gzip
Connection: close

1
-
a3
-04f67da35c831a08306078cd32c7bac8f906018e58c2bdbe56d05323a1b9
Content-Type: application/octet-stream
Content-Disposition: form-data; name="file"; filename=""


8000
<lots of binary data>

--04f67da35c831a08306078cd32c7bac8f906018e58c2bdbe56d05323a1b9--

0

Result

{"Name":"","Bytes":61252}
{"Name":"QmcLpF3adjhfBZMo6yxSNfYMfaPDbVxVTA3Hv3cAqTEc6i","Hash":"QmcLpF3adjhfBZMo6yxSNfYMfaPDbVxVTA3Hv3cAqTEc6i"}

Patch, PatchLink are broken

With go-ipfs 0.3.11 both Patch and PatchLink are broken. Running go test shows two failed tests: TestPatchLink and TestPatch_rmLink (which uses Patch to issue rm-link). This happens because Patch and PatchLink put the command in front of the root hash but the API expects the root hash to come first.

import conflict with floodsub

I have a go-libp2p-floodsub based project in which I would also like to utilize a locally running ipfs node for various pieces of functionality related to content distribution, to avoid needing to reinvent large parts of ipfs. However, it seems that this package cannot be used in the same project due to protobuf registrations issues.

With the following sample code:

package main

import (
	"fmt"

	_ "github.com/ipfs/go-ipfs-api"
	_ "github.com/libp2p/go-floodsub"
)

func main() {
	fmt.Println("Dear me...")
}

one can observe the following errors:

2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.RPC
2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.RPC.SubOpts
2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.Message
2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.TopicDescriptor
2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.TopicDescriptor.AuthOpts
2018/03/12 12:40:41 proto: duplicate proto type registered: floodsub.pb.TopicDescriptor.EncOpts
panic: proto: duplicate enum registered: floodsub.pb.TopicDescriptor_AuthOpts_AuthMode

Seems like go-ipfs-api imports go-libp2p-pubsub which is basically just a copy of the go-floodsub proto definitions. I can work around this on a fork that substitutes the import statements if need be, but wondering if the way forward is really to use a non-canonical source for the proto definitions....

Pin option for DagPut

I'm monkey patching DagPut to include a pin option and am curious if there's a reason it's not in there? Happy to try submitting a pr if y'all want the change.

No ability to send GET instead of POST requests?

Hello, I'm currently working on a service for my project that requests content through public gateways. Initially when I wrote my module I was getting failures from every gateway due to read-only APIs not allowing POST requests which I found strange since I was making cat command requests which should be GET requests. After digging around the code I found that all requests made are actually sent as POST requests.

req, err := http.NewRequest("POST", url, r.Body)

Is there any way to make GET requests short of creating a new Send function that makes GET requests?

General way to invoke all available commands with all options

It is very useful to have very clean go interfaces with nice typing. But right now the api is simply incomplete. We should have some fallback methods to be able to use any command and any option available, at the cost of complexity for the user.

For example, i want to use the trickledag layout, but i cannot call it because it hasn't been added to the nicer exported add commands. I don't see a way of doing it, and so instead i shelled out (gross). (yes, this should really just be contributed as we go, and we should source contributions this way, but the amount of time it takes to contribute this and bikeshed the interfaces is unreasonable for quick hacks).

I think that even as we work to a complete well-typed api, something like this should be possible:

s, err := shell.AddWithAnyOpts(r, map[string]interface{}{
  "trickle": true,
  "chunker": "rabin-512-1024-2048",
})

and potentially something like this:

func (s *shell) Cmd(cmd string, args []interface{}, opts map[string]interface{})

shell.Cmd("add", []interface{r}, map[string]interface{}{
  "trickle": true,
  "chunker": "rabin-512-1024-2048",
})

this would make it at worst case usable, instead of forcing us to shell out, or use js-api instead.

Any way to provide the key to use when publishing to IPNS?

I'm looking at https://github.com/ipfs/go-ipfs-api/blob/master/ipns.go#L9 and try to figure out how to specify the key to use for publishing the record?
I can see that on the api side the value can be red in theory: https://github.com/ipfs/go-ipfs/blob/master/core/coreapi/name.go#L42

I can implement that myself but I currently struggle to find the the point where https://github.com/ipfs/go-ipfs/blob/master/core/coreapi/name.go#L41 is invoked to see how the parameter needs to be formatted/named etc.

If someone can explain what I'm doing wrong or point me to the point where the http request is mapped to the coreapi function that would be awesome

Remove Shell.NetDiag

This function has been removed from the go-ipfs API, and should be removed here too.

Using HTTPS transport

What is the option to use TLS-driven IPFS node?
For example, Infura gives node https://ipfs.infura.io:5001/;

func NewShell(url string) *Shell {
	c := &gohttp.Client{
		Transport: &gohttp.Transport{
			Proxy:             gohttp.ProxyFromEnvironment,
			DisableKeepAlives: true,
		},
	}

	return NewShellWithClient(url, c)
}

Any suggestions?

use with go-ipfs/core - panic: Reuse of exported var name: utpAckSkippedResends

This code:
`package main

import (
"fmt"
_ "github.com/ipfs/go-ipfs-api"
_ "github.com/ipfs/go-ipfs/core"
)

func main() {
fmt.Println("test")
}`

Getting this error:

`2016/04/14 23:54:05 Reuse of exported var name: utpAckSkippedResends
panic: Reuse of exported var name: utpAckSkippedResends

goroutine 1 [running]:
log.Panicln(0xc8200d3db0, 0x2, 0x2)
/usr/local/go/src/log/log.go:334 +0xc1
expvar.Publish(0x5d39e0, 0x14, 0x20045c8, 0xc820073b10)
/usr/local/go/src/expvar/expvar.go:254 +0x233
expvar.NewInt(0x5d39e0, 0x14, 0xb)
/usr/local/go/src/expvar/expvar.go:272 +0x75
gx/ipfs/QmadkZhaLw1AhXKyBiPmydRuTexhj6WkiZPpo5Uks6WUVq/utp.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmadkZhaLw1AhXKyBiPmydRuTexhj6WkiZPpo5Uks6WUVq/utp/utp.go:52 +0x97
gx/ipfs/QmYVqhVfbK4BKvbW88Lhm26b3ud14sTBvcm1H7uWUx1Fkp/go-multiaddr-net/utp.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmYVqhVfbK4BKvbW88Lhm26b3ud14sTBvcm1H7uWUx1Fkp/go-multiaddr-net/utp/utp_util.go:105 +0x45
gx/ipfs/QmYVqhVfbK4BKvbW88Lhm26b3ud14sTBvcm1H7uWUx1Fkp/go-multiaddr-net.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmYVqhVfbK4BKvbW88Lhm26b3ud14sTBvcm1H7uWUx1Fkp/go-multiaddr-net/net.go:298 +0x56
gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/net/conn.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/net/conn/secure_conn.go:124 +0x60
gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/net.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/net/interface.go:155 +0x40
gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/host.init()
/Users/alexandervielimchanitsia/go/src/gx/ipfs/QmccGfZs3rzku8Bv6sTPH3bMUKD1EVod8srgRjt5csdmva/go-libp2p/p2p/host/host.go:64 +0x5b
github.com/ipfs/go-ipfs/core.init()
/Users/alexandervielimchanitsia/go/src/github.com/ipfs/go-ipfs/core/pathresolver.go:91 +0x6a
main.init()
/Users/alexandervielimchanitsia/Documents/xxx/xxx/service/host.go:11 +0x45

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1721 +0x1

goroutine 20 [syscall]:
os/signal.loop()
/usr/local/go/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
/usr/local/go/src/os/signal/signal_unix.go:28 +0x37

goroutine 21 [select]:
gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log.(*MirrorWriter).logRoutine(0xc82006e940)
/Users/alexandervielimchanitsia/go/src/gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log/writer.go:71 +0x33c
created by gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log.NewMirrorWriter
/Users/alexandervielimchanitsia/go/src/gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log/writer.go:38 +0xe2`

run time error

When I am running a function which uses Cat from go-ipfs-api I am getting the following error:
http: panic serving 127.0.0.1:47824: runtime error: slice bounds out of range
goroutine 21 [running]:
net/http.(*conn).serve.func1(0xc4200c6a00)
/usr/lib/go-1.10/src/net/http/server.go:1726 +0x11b
panic(0x9b5360, 0xd99280)
/usr/lib/go-1.10/src/runtime/panic.go:502 +0x24a

I am working on ubuntu

trying to pull range requests with IPFS client code

I copied some patterns I saw in this library, and thought that this must be the way to do it.

I get a request, and set Range on the header. I call an almost identical provider that wraps S3, and range request in this format works. I should get the file seeked up to lo. Is this supposed to work with IPFS?

	req := r.Shell.Request("cat", string(n))
	req.Header("Range", fmt.Sprintf("bytes=%d-%d", lo, hi))
	res, err := req.Send(context.Background())

Also, when pulling huge media, client disconnects are very common. Browsers will pull the first 100k or so of a video just to figure out what it is, and cut off the connection. So, client disconnects are not logged as errors, because if the server yields a 200 or a 206, it is doing its end of the contract and sending bytes back. It's not required that the client consume all the bytes.


```00:56:22.025 ERROR  cmds/http: write tcp4 127.0.0.1:5001->127.0.0.1:54520: write: connection reset by peer responseemitter.go:132
00:56:22.082 ERROR  cmds/http: write tcp4 127.0.0.1:5001->127.0.0.1:54522: write: broken pipe responseemitter.go:132
00:57:02.216 ERROR  cmds/http: write tcp4 127.0.0.1:5001->127.0.0.1:54554: write: connection reset by peer responseemitter.go:132
01:08:50.813 ERROR  cmds/http: write tcp4 127.0.0.1:5001->127.0.0.1:55984: write: connection reset by peer responseemitter.go:132
01:09:44.471 ERROR  cmds/http: write tcp4 127.0.0.1:5001->127.0.0.1:56008: write: connection reset by peer responseemitter.go:132

How to calculate CID of file data?

I'm currently trying to figure out how I can calculate the content hash of a file, without adding it to IPFS. I took a look at the code for the Shell.Add function, however it forwards the request onto ipfs itself, waiting for the returned response to retrieve the hash. What I'm attempting to do is calculate the hash of a file to be able to send that to a user, followed by uploading the hash to my ipfs node. The reason I want to caluclate the hash before uploading it to IPFS, is that this will be quicker to send them a response, instead of say having to wait for an entire 10GB file to be pinned to IPFS.

Requesting Simple Examples on Main Page

Ok - I have to admit I'm totally lost.

What I would like to do is seemingly trivial - I have a go application inside a docker container and I would like the ability to add messages to ipfs, store the hash for later retrieval, and later retrieve them. Here are all the resources I've looked into to try and figure out how to solve this problem:

https://discuss.ipfs.io/ - Lots of dead threads and general discussion/nontechnical.

https://docs.ipfs.io/introduction/usage/ Great examples! Except it all works from the command line.

https://ipfs.io/blog/1-run-ipfs-on-docker/ - This is closer, however with caveats. Written a couple years ago, not 100% certain it is still relevant. Also, it all works by execing into Docker. Finally, it appears to work with the http curl commands, and not a go hook.

https://github.com/gnosis/pm-trading-db - I guess I could try and back out what these guys did, but it looks complicated.

Does anyone have any advice?

Examples?

Are there usage examples? dont see any in the repo

Connectivity within Nodes

Connectivity within Nodes

Hi,

Can you please guide us on below usecase ?

We are working on P2P network implementation over go-ipfs
We have our own bootstrap nodes for creating network
We need to have seamless discovery + DHT + Ping and pubsub within them

Below are challenges we are experiencing :

  1. We are able to get list of all DHT providers for specific CID (content id)

  2. When we try to ping particular node using ID ping fails
    (Ping error: dial attempt failed: <peer.ID cwB1fj> -->
    <peer.ID cncwpp> dial attempt failed: dial tcp4 173.18.0.1:4001: i/o timeout)

and

Error: connect QmWmfowSaHDSzHoeDXAq1jWioc2vSMrr9ZoncK3VqTBDRL failure: dial attempt
failed: <peer.ID ay2YAo> --> <peer.ID WmfowS> dial attempt failed: dial tcp4
53.20.142.177:55783: connectex: No connection could be made because the target
machine actively refused it.

Some Notes:
We are using go-ipfs latest version
We are behind NAT this case was tried on Ec2 with all open ports on provider side

Idiomatic "DefaultShell"

In most tools, i want to:

  • default to use a locally available ipfs node
  • default to use the global ipfs-gateway

in these cases, it would be nice to have something like:

import ipfs "github.com/ipfs/go-ipfs-api"

ipfsNode, err := ipfs.DefaultNode()

that does this for me.

PubSubSubscription receives empty message on subscription?

Hello I'm very new to IPFS and haven't had the time to dig into the code but I've been observing an odd but consistent behaviour where a call to the first PubSubSubscription.Next() immediately yields an empty PubSubRecord object. Here is a minimal example that replicates this phenomena on the two Macs I've tested it on:

package main

import (
  "fmt"
  "log"

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

func main() {
  ipfs := shell.NewShell("/ip4/127.0.0.1/tcp/5001")

  sub, err := ipfs.PubSubSubscribe("somerandomtopicthatijustmadeupforthispurpose")

  if err != nil {
    log.Fatal(err)
  }

  rec, err := sub.Next()

  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(len(rec.Data()))
}

Is this intended and/or consistent behaviour? If it is consistent I can work around this but if it is not I might run into some issues.

PubSubPublish returns a non-nil error wraps a nil error.

func (s *Shell) PubSubPublish(topic, data string) (err error) {
resp, err := s.Request("pubsub/pub", topic, data).Send(context.Background())
if err != nil {
return err
}
defer resp.Close()

  • if resp.Error == nil {
  • return nil
  • }
    return resp.Error
    }

Without adding the three lines shown above, this function will return a non-nil error with wraps a nil resp.Error. The reason is that the error interface includes a nil is not nil itself. https://golang.org/doc/faq#nil_error

Add --discover flag in PubSubSubscribe parameters

It has come to my attention that using the --discover flag on PubSubSubscribe is not possible. Adding an option to the method would be quite trivial and should be done for increased functionality.

Modify tests to start daemon before running?

Currently to run the tests, you'll need to manually start a daemon locally, otherwise all of them will fail.

Is it possible we can start some testing daemon before running the tests, from within the tests so users don't have to think about it?

DagPut broken in 1.2.0

I just upgraded this repo to 1.2.0 to fix the AddDir bug and now:

package main

import (
	"log"

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

func main() {
	s := shell.NewLocalShell()
	obj, err := s.DagPut(`{"x": "abc","y":"def"}`, "json", "cbor")
	if err != nil {
		log.Panic(err)
	}
	log.Println(obj)
}
2017/11/23 22:41:31 dag/put: File argument 'object data' is required
panic: dag/put: File argument 'object data' is required

I haven't replaced the daemon. Still running the same version

issue regarding function

Can I create app ID using go ipfs api? Is there any function to do this? If not can we have a function included in go ipfs api to create app id?

Create 1.3.0 release

Version 1.3.0 was released for gx but not as a github release. Would be great if you could add this one, too.

AddDir creates object with no links (but only data)

I assumed sh.AddDir would end up returning a hash that is usable with sh.List (ls). This appears not to be the case. I get an object like this:
{"Links":[],"Data":"\u0008\u0002\u0012?\u0007--95a955e5bfb13034cd6b0f1d6fece94172647b39db9122b368ae146fc248\r\nContent-Disposition: file; filename=\"1_emptydir\"\r\nContent-T.......

Is this a bug?

Code example:
https://gist.github.com/kalmi/f5c54c8261c327f6b8ed4187e2f53a02 (complete unexpected output at the bottom in a comment)

plumb context

Allowing context to be specified per-operation means requests can be timed out consistently as well as allowing for cancelation when doing parallel requests with something like errgroup.

Global Gateway?

Is there a way to use the global gateway w/ Shell, in a ReadOnly mode?

Is Shell.Pin recursive by default?

Took a look and I might be missing something but I can't seem to find a definitive answer as to whether or not Shell.Pin uses recursive pins by default. I see that here

req.Opts["r"] = "true"
there is an enabling of the r option which I assume is recursive?

Rename as go-ipfs-api

To follow with the other languages, we should rename this package as "go-ipfs-api". heads up before i do it, so you've some notice the pkg will change names.

Rename "shell" to "node" for ease of use?

I really like the "shell" name. But the IPFS api uses the naming "Node". to comply with that we should either switch or expose a "Node" type or functions or even a package that translates the wording.

Difficult to add links to directory

I'm new and trying out IPFS for the first time. I have a directory in IPFS that I've added from the command line using ipfs add -r. My objective is to write a go program that adds a file to that directory, and gives me the hash of the resulting directory. I can add the file to IPFS using the Add function, so all that's left to do is add the hash of the file to the directory as another link.

The trouble is that I can't find a way to do this efficiently using the API. I see an AddDir function, but ideally I don't want to have to download the entire directory tree, add my file, and then re-upload it, because the directory tree could be very large.

In terms of the Merkle DAG, what I want to do is create a copy of the object representing the directory, while adding an additional link. While there are functions that would let me do this in the API, it seems that they operate at the object level, and therefore do not correctly encode things to fit the filesystem abstraction (e.g., Size is not set correctly on links, bytes are not set correctly in the body of a directory, etc.)

I'm new to IPFS so it's possible I'm overlooking an obvious way to do this. Is there a way to add a new file to a directory without having to download the entire directory tree, using the go API? And if not, what are some workarounds I could use?

PubSub tests hang with go-ipfs master

Example: https://travis-ci.org/ipfs/go-ipfs-api/jobs/304527816

This seems to have started with the merge of ipfs/kubo#3856.

I changed the t.Log() calls to fmt.Printf() locally, and saw that it's hanging at subscribing..., and Wireshark tells me that the API doesn't bother sending response header until the first message comes in (which I emulated with ipfs pubsub pub test foobar).

=== RUN   TestAdd
--- PASS: TestAdd (0.00s)
=== RUN   TestLocalShell
--- PASS: TestLocalShell (0.00s)
=== RUN   TestCat
--- PASS: TestCat (0.00s)
=== RUN   TestList
--- PASS: TestList (0.00s)
=== RUN   TestFileList
--- PASS: TestFileList (0.00s)
=== RUN   TestPins
--- PASS: TestPins (0.01s)
=== RUN   TestPatch_rmLink
--- PASS: TestPatch_rmLink (0.00s)
=== RUN   TestPatchLink
--- PASS: TestPatchLink (0.00s)
=== RUN   TestResolvePath
--- PASS: TestResolvePath (0.00s)
=== RUN   TestPubSub
subscribing...

needs tests

Would be good to actually get some tests running for this, and then set up travis CI

runtime error: invalid memory address or nil pointer dereference

When I am running a program which is for a web response I am getting a run time error as follows :

http: panic serving 127.0.0.1:43802: runtime error: invalid memory address or nil pointer dereference
goroutine 6 [running]:
net/http.(conn).serve.func1(0xc4200a4a00)
/usr/lib/go-1.10/src/net/http/server.go:1726 +0x11b
panic(0x9b5360, 0xd99230)
/usr/lib/go-1.10/src/runtime/panic.go:502 +0x24a
github.com/ipfs/go-ipfs-api.(RequestBuilder).Send(0xc4201740a0, 0xb95c60, 0xc420022100, 0x0, 0x0, 0x0)
The code is as follows :
func main() {
router := httprouter.New()
router.RedirectTrailingSlash = true
c := cors.New(cors.Options{
AllowedOrigins: []string{"
"},
AllowedMethods: []string{"GET", "POST", "OPTIONS", "Authorization"},
AllowedHeaders: []string{"
"},
AllowCredentials: true,
})
router.GET("/create", StoreAndGetHash)
router.GET("/read/:hashvalue", GetFile)
router.GET("/appdata/:appID", ReadPeer)
router.GET("/update", UpdateAndGetHash)
router.GET("/createdir", GetDir)
router.GET("/newkey", GetNewKey)

log.Fatal(http.ListenAndServe(":3000", c.Handler(router)))

}

func StoreAndGetHash(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var read io.Reader
Shell := shell.NewLocalShell()
path := r.URL.Query().Get("path")
typedata := r.URL.Query().Get("mime")
data := r.URL.Query().Get("content")
if typedata != "" && data != "" {
data = strings.Replace(data, " ", "+", -1)
content := typedata + ";" + data
file := []byte(content)
read = bytes.NewReader(file)
} else if path != "" {
file, _ := os.Open(path)
read = io.Reader(file)
}
hash, err := Shell.Add(read)
if err != nil {
util.WebResponse(w, r, http.StatusNotFound, "")
return
}
util.WebResponse(w, r, http.StatusOK, hash)
return

}

Add Directory with hidden subfolders and files

When I'm adding a directory to IPFS with the AddDir(dir) command, there is no option to add hidden files or directories like .git or .gitignore. So I added an option to the codebase like in the snippet below. The problem is that this doesn't work for some reason. Am I just missing something or is this a bug?

func (s *Shell) AddDir(dir string, hidden bool) (string, error) {
	stat, err := os.Lstat(dir)
	if err != nil {
		return "", err
	}

	sf, err := files.NewSerialFile(path.Base(dir), dir, false, stat)
	if err != nil {
		return "", err
	}
	slf := files.NewSliceFile("", dir, []files.File{sf})
	reader := files.NewMultiFileReader(slf, true)

	resp, err := s.Request("add").
		Option("recursive", true).
		Option("hidden", true).
		Body(reader).
		Send(context.Background())

	if err != nil {
		return "", nil
	}
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.