Skip to content

Commit bb64304

Browse files
Fix: README.md
1 parent 65c27aa commit bb64304

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ Simple Tezos RPC API wrapper.
5656
import "github.com/dipdup-net/go-lib/node"
5757

5858
rpc := node.NewNodeRPC(url, node.WithTimeout(timeout))
59+
60+
ctx, cancel := context.WithCancel(context.Background())
61+
defer cancel()
62+
63+
// example with context
64+
constants, err := rpc.Constants(node.WithContext(ctx))
65+
if err != nil {
66+
panic(err)
67+
}
68+
69+
// example without context
70+
constants, err := rpc.Constants()
71+
if err != nil {
72+
panic(err)
73+
}
74+
5975
```
6076

6177
### `database`
@@ -105,7 +121,7 @@ There are 2 default implementations of `Database` interface:
105121

106122
There is method `Wait` which waiting until database connection will be established.
107123

108-
Exaple of usage:
124+
Example of usage:
109125

110126
```go
111127
ctx, cancel := context.WithCancel(context.Background())
@@ -115,6 +131,7 @@ db := database.NewPgGo()
115131
if err := db.Connect(ctx, cfg); err != nil {
116132
panic(err)
117133
}
134+
defer db.Close()
118135

119136
database.Wait(ctx, db, 5*time.Second)
120137

@@ -212,21 +229,13 @@ func main() {
212229
Example usage of the API wrapper:
213230

214231
```go
215-
package main
216-
217-
import (
218-
"log"
232+
ctx, cancel := context.WithCancel(context.Background())
233+
defer cancel()
219234

220-
"github.com/dipdup-net/go-lib/tzkt/api"
221-
)
235+
tzkt := api.New("url here")
222236

223-
func main() {
224-
tzkt := api.New("url here")
225-
226-
head, err := tzkt.GetHead()
227-
if err != nil {
228-
log.Panic(err)
229-
}
230-
log.Println(head)
237+
head, err := tzkt.GetHead(ctx)
238+
if err != nil {
239+
log.Panic(err)
231240
}
232241
```

0 commit comments

Comments
 (0)