Skip to content
This repository has been archived by the owner on Jul 5, 2021. It is now read-only.

Commit

Permalink
Gofmt's example code in readme's
Browse files Browse the repository at this point in the history
  • Loading branch information
eelcocramer committed Oct 20, 2015
1 parent fc09e3a commit 82e8fe1
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 177 deletions.
106 changes: 53 additions & 53 deletions examples/api/demoapp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ To Start off, lets get some imports:
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"code.google.com/p/go.net/context"
"bufio"
"fmt"
"io"
"os"
"code.google.com/p/go.net/context"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/repo/fsrepo"
)
```

Expand All @@ -27,38 +27,38 @@ Now, lets make a quick function to do a frequency count on characters:

```
func CountChars(r io.Reader) map[byte]int {
m := make(map[byte]int)
buf := bufio.NewReader(r)
for {
b, err := buf.ReadByte()
if err != nil {
return m
}
m[b]++
}
m := make(map[byte]int)
buf := bufio.NewReader(r)
for {
b, err := buf.ReadByte()
if err != nil {
return m
}
m[b]++
}
}
```

Alright, now for the ipfs goodness:

```
func SetupIpfs() (*core.IpfsNode, error) {
// Assume the user has run 'ipfs init'
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
return nil, err
}
cfg := &core.BuildCfg {
Repo: r,
Online: true,
}
cfg := new(core.BuildCfg)
cfg.Repo = r
cfg.Online = true
return core.NewNode(context.Background(), cfg)
// Assume the user has run 'ipfs init'
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
return nil, err
}
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
cfg := new(core.BuildCfg)
cfg.Repo = r
cfg.Online = true
return core.NewNode(context.Background(), cfg)
}
```

Expand All @@ -67,25 +67,25 @@ doing something.

```
func main() {
nd, err := SetupIpfs()
if err != nil {
fmt.Println(err)
return
}
if len(os.Args) < 2 {
fmt.Println("Please pass in an argument!")
return
}
keytofetch := os.Args[1]
read, err := coreunix.Cat(nd, keytofetch)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(CountChars(read))
nd, err := SetupIpfs()
if err != nil {
fmt.Println(err)
return
}
if len(os.Args) < 2 {
fmt.Println("Please pass in an argument!")
return
}
keytofetch := os.Args[1]
read, err := coreunix.Cat(nd, keytofetch)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(CountChars(read))
}
```

Expand Down
72 changes: 36 additions & 36 deletions examples/api/randobj/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ First, lets get some imports:
package main
import (
"io"
"net/http"
"os"
"io"
"net/http"
"os"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/repo/fsrepo"
u "github.com/ipfs/go-ipfs/util"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/repo/fsrepo"
u "github.com/ipfs/go-ipfs/util"
"code.google.com/p/go.net/context"
"code.google.com/p/go.net/context"
)
```

Expand All @@ -33,15 +33,15 @@ Now, lets write the http handler func for generating our random objects.

```
func ServeIpfsRand(w http.ResponseWriter, r *http.Request) {
read := io.LimitReader(u.NewTimeSeededRand(), 2048)
str, err := coreunix.Add(gnode, read)
if err != nil {
w.WriteHeader(504)
w.Write([]byte(err.Error()))
} else {
w.Write([]byte(str))
}
read := io.LimitReader(u.NewTimeSeededRand(), 2048)
str, err := coreunix.Add(gnode, read)
if err != nil {
w.WriteHeader(504)
w.Write([]byte(err.Error()))
} else {
w.Write([]byte(str))
}
}
```

Expand All @@ -51,38 +51,38 @@ Set up our node configuration, and use the users standard ipfs configuration dir

```
func main() {
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
```

Now we need to set up our context

```
// Make our 'master' context and defer cancelling it
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Make our 'master' context and defer cancelling it
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
```

Then create a configuration and finally create our node!

```
cfg := &core.BuildCfg {
Repo: r,
Online: true,
}
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
node, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
node, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
// Set the global node for access in the handler
gnode = node
// Set the global node for access in the handler
gnode = node
http.HandleFunc("/ipfsobject", ServeIpfsRand)
http.ListenAndServe(":8080", nil)
http.HandleFunc("/ipfsobject", ServeIpfsRand)
http.ListenAndServe(":8080", nil)
}
```

Expand Down
10 changes: 5 additions & 5 deletions examples/api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The above code snippet is the simplest way to create an ipfs node. Below is expl
Lets create a Node's build configuration:

```
cfg := &core.BuildCfg {
Repo: r,
Online: true,
Routing: myRoutingOption,
cfg := &core.BuildCfg{
Repo: r,
Online: true,
Routing: myRoutingOption,
}
```

Expand All @@ -43,7 +43,7 @@ import "github.com/ipfs/go-ipfs/repo/fsrepo"
.
r := fsrepo.Open("/path/to/.ipfs")
if err != nil {
// Deal with the error
// Deal with the error
}
```

Expand Down
Loading

0 comments on commit 82e8fe1

Please sign in to comment.