Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit b0de2b0

Browse files
PedrobyJoaoJPexplorer
andauthored
docs: adding example of connection and pinning to README (#173)
Co-authored-by: JPexplorer <[email protected]>
1 parent 81c4b4d commit b0de2b0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ greatest features, please use _this_ package.
1717

1818
https://godoc.org/github.com/ipfs/go-ipfs-http-api
1919

20+
### Example
21+
22+
Pin file on your local IPFS node based on its CID:
23+
24+
```go
25+
package main
26+
27+
import (
28+
"context"
29+
"fmt"
30+
31+
ipfsClient "github.com/ipfs/go-ipfs-http-client"
32+
path "github.com/ipfs/interface-go-ipfs-core/path"
33+
)
34+
35+
func main() {
36+
// "Connect" to local node
37+
node, err := ipfsClient.NewLocalApi()
38+
if err != nil {
39+
fmt.Printf(err)
40+
return
41+
}
42+
// Pin a given file by its CID
43+
ctx := context.Background()
44+
cid := "bafkreidtuosuw37f5xmn65b3ksdiikajy7pwjjslzj2lxxz2vc4wdy3zku"
45+
p := path.New(cid)
46+
err = node.Pin().Add(ctx, p)
47+
if err != nil {
48+
fmt.Printf(err)
49+
return
50+
}
51+
return
52+
}
53+
```
54+
2055
## Contribute
2156

2257
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/go-ipfs-http-api/issues)!

0 commit comments

Comments
 (0)