diff --git a/.circleci/config.yml b/.circleci/config.yml index 998d31418323..023f1ef9fa2b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,6 +101,9 @@ jobs: - run: when: always command: bash <(curl -s https://codecov.io/bash) -cF unittests -X search -f coverage/unit_tests.coverprofile + - run: + command: go test -v ./... + working_directory: ~/ipfs/go-ipfs/docs/examples/go-ipfs-as-a-library - run: when: always diff --git a/docs/examples/go-ipfs-as-a-library/example-folder/ipfs.paper.draft3.pdf b/docs/examples/example-folder/ipfs.paper.draft3.pdf similarity index 100% rename from docs/examples/go-ipfs-as-a-library/example-folder/ipfs.paper.draft3.pdf rename to docs/examples/example-folder/ipfs.paper.draft3.pdf diff --git a/docs/examples/go-ipfs-as-a-library/example-folder/test-dir/ipfs-logo.png b/docs/examples/example-folder/test-dir/ipfs-logo.png similarity index 100% rename from docs/examples/go-ipfs-as-a-library/example-folder/test-dir/ipfs-logo.png rename to docs/examples/example-folder/test-dir/ipfs-logo.png diff --git a/docs/examples/go-ipfs-as-a-library/example-folder/test-dir/ipfs.paper.draft3.pdf b/docs/examples/example-folder/test-dir/ipfs.paper.draft3.pdf similarity index 100% rename from docs/examples/go-ipfs-as-a-library/example-folder/test-dir/ipfs.paper.draft3.pdf rename to docs/examples/example-folder/test-dir/ipfs.paper.draft3.pdf diff --git a/docs/examples/go-ipfs-as-a-library/go.mod b/docs/examples/go-ipfs-as-a-library/go.mod index 9520a04bedd8..024e3a063b17 100644 --- a/docs/examples/go-ipfs-as-a-library/go.mod +++ b/docs/examples/go-ipfs-as-a-library/go.mod @@ -1,14 +1,13 @@ module github.com/ipfs/go-ipfs/examples/go-ipfs-as-a-library -go 1.14 +go 1.15 require ( - github.com/ipfs/go-ipfs v0.7.0 + github.com/ipfs/go-ipfs v0.9.1 github.com/ipfs/go-ipfs-config v0.14.0 github.com/ipfs/go-ipfs-files v0.0.8 github.com/ipfs/interface-go-ipfs-core v0.4.0 github.com/libp2p/go-libp2p-core v0.8.6 - github.com/libp2p/go-libp2p-peerstore v0.2.8 github.com/multiformats/go-multiaddr v0.3.3 ) diff --git a/docs/examples/go-ipfs-as-a-library/go.sum b/docs/examples/go-ipfs-as-a-library/go.sum index 58a074f4c852..1e4748e1cb57 100644 --- a/docs/examples/go-ipfs-as-a-library/go.sum +++ b/docs/examples/go-ipfs-as-a-library/go.sum @@ -423,8 +423,8 @@ github.com/ipfs/go-ipfs-files v0.0.8 h1:8o0oFJkJ8UkO/ABl8T6ac6tKF3+NIpj67aAB6Zpu github.com/ipfs/go-ipfs-files v0.0.8/go.mod h1:wiN/jSG8FKyk7N0WyctKSvq3ljIa2NNTiZB55kpTdOs= github.com/ipfs/go-ipfs-keystore v0.0.2 h1:Fa9xg9IFD1VbiZtrNLzsD0GuELVHUFXCWF64kCPfEXU= github.com/ipfs/go-ipfs-keystore v0.0.2/go.mod h1:H49tRmibOEs7gLMgbOsjC4dqh1u5e0R/SWuc2ScfgSo= -github.com/ipfs/go-ipfs-pinner v0.1.1 h1:iJd1gwILGQJSZhhI0jn6yFOLg34Ua7fdKcB6mXp6k/M= -github.com/ipfs/go-ipfs-pinner v0.1.1/go.mod h1:EzyyaWCWeZJ/he9cDBH6QrEkSuRqTRWMmCoyNkylTTg= +github.com/ipfs/go-ipfs-pinner v0.1.2 h1:Ve9OBhL6eg5+tVqEnIhPZOCXDtMjB+OhOohVZxPUxms= +github.com/ipfs/go-ipfs-pinner v0.1.2/go.mod h1:/u9kMe+TyQybN21O5OBicdyx3x93lVI77PCtiTnArUk= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY= diff --git a/docs/examples/go-ipfs-as-a-library/main.go b/docs/examples/go-ipfs-as-a-library/main.go index 2a0483edafd4..b7c1537ddd77 100644 --- a/docs/examples/go-ipfs-as-a-library/main.go +++ b/docs/examples/go-ipfs-as-a-library/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "fmt" "io/ioutil" "log" @@ -57,6 +58,24 @@ func createTempRepo() (string, error) { return "", err } + // When creating the repository, you can define custom settings on the repository, such as enabling experimental + // features (See experimental-features.md) or customizing the gateway endpoint. + // To do such things, you should modify the variable `cfg`. For example: + if *flagExp { + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-filestore + cfg.Experimental.FilestoreEnabled = true + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-urlstore + cfg.Experimental.UrlstoreEnabled = true + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#directory-sharding--hamt + cfg.Experimental.ShardingEnabled = true + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-p2p + cfg.Experimental.Libp2pStreamMounting = true + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#p2p-http-proxy + cfg.Experimental.P2pHttpProxy = true + // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#strategic-providing + cfg.Experimental.StrategicProviding = true + } + // Create the repo with the config err = fsrepo.Init(repoPath, cfg) if err != nil { @@ -198,7 +217,11 @@ func getUnixfsNode(path string) (files.Node, error) { /// ------- +var flagExp = flag.Bool("experimental", false, "enable experimental features") + func main() { + flag.Parse() + /// --- Part I: Getting a IPFS node running fmt.Println("-- Getting an IPFS node running -- ") @@ -228,7 +251,7 @@ func main() { fmt.Println("\n-- Adding and getting back files & directories --") - inputBasePath := "./example-folder/" + inputBasePath := "../example-folder/" inputPathFile := inputBasePath + "ipfs.paper.draft3.pdf" inputPathDirectory := inputBasePath + "test-dir" @@ -258,7 +281,11 @@ func main() { /// --- Part III: Getting the file and directory you added back - outputBasePath := "./example-folder/" + outputBasePath, err := ioutil.TempDir("", "example") + if err != nil { + panic(fmt.Errorf("could not create output dir (%v)", err)) + } + fmt.Printf("output folder: %s\n", outputBasePath) outputPathFile := outputBasePath + strings.Split(cidFile.String(), "/")[2] outputPathDirectory := outputBasePath + strings.Split(cidDirectory.String(), "/")[2] diff --git a/docs/examples/go-ipfs-as-a-library/main_test.go b/docs/examples/go-ipfs-as-a-library/main_test.go new file mode 100644 index 000000000000..ec34d62b1a93 --- /dev/null +++ b/docs/examples/go-ipfs-as-a-library/main_test.go @@ -0,0 +1,17 @@ +package main + +import ( + "os/exec" + "strings" + "testing" +) + +func TestExample(t *testing.T) { + out, err := exec.Command("go", "run", "main.go").Output() + if err != nil { + t.Fatalf("running example (%v)", err) + } + if !strings.Contains(string(out), "All done!") { + t.Errorf("example did not run successfully") + } +} diff --git a/docs/examples/library-experimental-features/README.md b/docs/examples/library-experimental-features/README.md deleted file mode 100644 index a351706951b3..000000000000 --- a/docs/examples/library-experimental-features/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# Use go-ipfs as a library and enable experimental features - -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) -as it gives insights on how to create a repository, the daemon and add a file. - -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): - -```go -func createTempRepo(ctx context.Context) (string, error) { - repoPath, err := ioutil.TempDir("", "ipfs-shell") - if err != nil { - return "", fmt.Errorf("failed to get temp dir: %s", err) - } - - // Create a config with default options and a 2048 bit key - cfg, err := config.Init(ioutil.Discard, 2048) - if err != nil { - return "", err - } - - // Create the repo with the config - err = fsrepo.Init(repoPath, cfg) - if err != nil { - return "", fmt.Errorf("failed to init ephemeral node: %s", err) - } - - return repoPath, nil -} -``` - -When creating the repository, you can define custom settings on the repository, such as enabling [experimental -features](../../experimental-features.md) or customizing the gateway endpoint. - -To do such things, you should modify the variable `cfg`. For example, to enable the sharding experiment, you would modify the function to: - -```go -func createTempRepo(ctx context.Context) (string, error) { - repoPath, err := ioutil.TempDir("", "ipfs-shell") - if err != nil { - return "", fmt.Errorf("failed to get temp dir: %s", err) - } - - // Create a config with default options and a 2048 bit key - cfg, err := config.Init(ioutil.Discard, 2048) - if err != nil { - return "", err - } - - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-filestore - cfg.Experimental.FilestoreEnabled = true - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-urlstore - cfg.Experimental.UrlstoreEnabled = true - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#directory-sharding--hamt - cfg.Experimental.ShardingEnabled = true - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-p2p - cfg.Experimental.Libp2pStreamMounting = true - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#p2p-http-proxy - cfg.Experimental.P2pHttpProxy = true - // https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#strategic-providing - cfg.Experimental.StrategicProviding = true - - // Create the repo with the config - err = fsrepo.Init(repoPath, cfg) - if err != nil { - return "", fmt.Errorf("failed to init ephemeral node: %s", err) - } - - return repoPath, nil -} -``` - -There are many other options that you can find through the [documentation](https://godoc.org/github.com/ipfs/go-ipfs-config#Config).