Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic fixups in examples #8325

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.