@cryptotaxi247 / kubo / commits / 9a9660e04

Create README.md

Henrique Dias committed Dec 11, 2019 at 17:53 UTC 9a9660e04ae5549ce3f35faa28dfc0b6c24f3f59
1 file changed +62
docs/examples/library-experimental-features/README.md new
+62
@@ -0,0 +1,62 @@
1 +# Use go-ipfs as a library and enable experimental features
2 +
3 +Before moving on to this tutorial, you must read first the initial [`go-ipfs` as a library tutorial](../go-ipfs-as-a-library/README.md)
4 +as it gives insights on how to create a repository, the daemon and add a file.
5 +
6 +There is only one thing that differs from this example and the first tutorial, which is the function [`createTempRepo`](../go-ipfs-as-a-library/main.go#L49):
7 +
8 +```go
9 +func createTempRepo(ctx context.Context) (string, error) {
10 + repoPath, err := ioutil.TempDir("", "ipfs-shell")
11 + if err != nil {
12 + return "", fmt.Errorf("failed to get temp dir: %s", err)
13 + }
14 +
15 + // Create a config with default options and a 2048 bit key
16 + cfg, err := config.Init(ioutil.Discard, 2048)
17 + if err != nil {
18 + return "", err
19 + }
20 +
21 + // Create the repo with the config
22 + err = fsrepo.Init(repoPath, cfg)
23 + if err != nil {
24 + return "", fmt.Errorf("failed to init ephemeral node: %s", err)
25 + }
26 +
27 + return repoPath, nil
28 +}
29 +```
30 +
31 +When creating the repository, you can define custom settings on the repository, such as enabling [experimental
32 +features](../../experimental-features.md) or customizing the gateway endpoint.
33 +
34 +To do such things, you should modify the variable `cfg`. For example, to enable the sharding experiment, you would modify the function to:
35 +
36 +```go
37 +func createTempRepo(ctx context.Context) (string, error) {
38 + repoPath, err := ioutil.TempDir("", "ipfs-shell")
39 + if err != nil {
40 + return "", fmt.Errorf("failed to get temp dir: %s", err)
41 + }
42 +
43 + // Create a config with default options and a 2048 bit key
44 + cfg, err := config.Init(ioutil.Discard, 2048)
45 + if err != nil {
46 + return "", err
47 + }
48 +
49 + // Customize configuration
50 + cfg.Experimental.ShardingEnabled = true
51 +
52 + // Create the repo with the config
53 + err = fsrepo.Init(repoPath, cfg)
54 + if err != nil {
55 + return "", fmt.Errorf("failed to init ephemeral node: %s", err)
56 + }
57 +
58 + return repoPath, nil
59 +}
60 +```
61 +
62 +There are many other options that you can find through the [documentation](https://godoc.org/github.com/ipfs/go-ipfs-config#Config).