Skip to content

Commit

Permalink
Cosmetic fixups in examples (#8325)
Browse files Browse the repository at this point in the history
* test the examples in CI
* combine the two examples into a single one

(cherry picked from commit c9cc09f)
  • Loading branch information
petar authored and aschmahmann committed Sep 27, 2021
1 parent 356cfd7 commit cb4006b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/go-ipfs-as-a-library/go.mod
Original file line number Diff line number Diff line change
@@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/go-ipfs-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
31 changes: 29 additions & 2 deletions docs/examples/go-ipfs-as-a-library/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 -- ")
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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]

Expand Down
17 changes: 17 additions & 0 deletions docs/examples/go-ipfs-as-a-library/main_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
72 changes: 0 additions & 72 deletions docs/examples/library-experimental-features/README.md

This file was deleted.

0 comments on commit cb4006b

Please sign in to comment.