@cryptotaxi247 / kubo / commits / 5c21cf0ce

docs: adding example of connection and pinning to README (#173)

Co-authored-by: JPexplorer <jpexplorer@pop-os.localdomain> This commit was moved from ipfs/go-ipfs-http-client@b0de2b028e6ef03d4dba3ed105641ad299d4f7be

João Pedro committed Mar 28, 2023 at 07:38 UTC 5c21cf0ce95d7c2710d5bb5dd58e2871c0fbc7bb
1 file changed +35
client/httpapi/README.md
+35
@@ -17,6 +17,41 @@ greatest features, please use _this_ package.
17
18 https://godoc.org/github.com/ipfs/go-ipfs-http-api
19
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 +
55 ## Contribute
56
57 Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/go-ipfs-http-api/issues)!