Skip to content

Commit 0673a35

Browse files
committed
readme: move uuid example to tests
Make example executable by adding reference output to the comments.
1 parent f408959 commit 0673a35

File tree

2 files changed

+55
-47
lines changed

2 files changed

+55
-47
lines changed

README.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ faster than other packages according to public benchmarks.
2323
* [API reference](#api-reference)
2424
* [Walking\-through example](#walking-through-example)
2525
* [Help](#help)
26-
* [Usage](#usage)
2726
* [Schema](#schema)
2827
* [Custom (un)packing and typed selects and function calls](#custom-unpacking-and-typed-selects-and-function-calls)
2928
* [Options](#options)
@@ -172,52 +171,6 @@ To contact `go-tarantool` developers on any problems, create an issue at
172171
The developers of the [Tarantool server](http://github.com/tarantool/tarantool)
173172
will also be happy to provide advice or receive feedback.
174173

175-
## Usage
176-
177-
To enable support of UUID in msgpack with [google/uuid](https://github.com/google/uuid),
178-
import tarantool/uuid submodule.
179-
```go
180-
package main
181-
182-
import (
183-
"log"
184-
"time"
185-
186-
"github.com/tarantool/go-tarantool"
187-
_ "github.com/tarantool/go-tarantool/uuid"
188-
"github.com/google/uuid"
189-
)
190-
191-
func main() {
192-
server := "127.0.0.1:3013"
193-
opts := tarantool.Opts{
194-
Timeout: 500 * time.Millisecond,
195-
Reconnect: 1 * time.Second,
196-
MaxReconnects: 3,
197-
User: "test",
198-
Pass: "test",
199-
}
200-
client, err := tarantool.Connect(server, opts)
201-
if err != nil {
202-
log.Fatalf("Failed to connect: %s", err.Error())
203-
}
204-
205-
spaceNo := uint32(524)
206-
207-
id, uuidErr := uuid.Parse("c8f0fa1f-da29-438c-a040-393f1126ad39")
208-
if uuidErr != nil {
209-
log.Fatalf("Failed to prepare uuid: %s", uuidErr)
210-
}
211-
212-
resp, err := client.Replace(spaceNo, []interface{}{ id })
213-
214-
log.Println("UUID tuple replace")
215-
log.Println("Error", err)
216-
log.Println("Code", resp.Code)
217-
log.Println("Data", resp.Data)
218-
}
219-
```
220-
221174
## Schema
222175

223176
```go

uuid/example_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// To enable support of UUID in msgpack with
2+
// [google/uuid](https://github.com/google/uuid), import tarantool/uuid
3+
// submodule.
4+
//
5+
// Run Tarantool instance before example execution:
6+
// $ cd uuid
7+
// $ TT_LISTEN=3013 TT_WORK_DIR=$(mktemp -d -t 'tarantool.XXX') tarantool config.lua
8+
// $ go test -v example_test.go
9+
//
10+
package uuid_test
11+
12+
import (
13+
"fmt"
14+
"log"
15+
"time"
16+
17+
"github.com/google/uuid"
18+
"github.com/tarantool/go-tarantool"
19+
_ "github.com/tarantool/go-tarantool/uuid"
20+
)
21+
22+
func Example() {
23+
server := "127.0.0.1:3013"
24+
opts := tarantool.Opts{
25+
Timeout: 500 * time.Millisecond,
26+
Reconnect: 1 * time.Second,
27+
MaxReconnects: 3,
28+
User: "test",
29+
Pass: "test",
30+
}
31+
client, err := tarantool.Connect(server, opts)
32+
if err != nil {
33+
log.Fatalf("Failed to connect: %s", err.Error())
34+
}
35+
36+
spaceNo := uint32(524)
37+
38+
id, uuidErr := uuid.Parse("c8f0fa1f-da29-438c-a040-393f1126ad39")
39+
if uuidErr != nil {
40+
log.Fatalf("Failed to prepare uuid: %s", uuidErr)
41+
}
42+
43+
resp, err := client.Replace(spaceNo, []interface{}{id})
44+
45+
fmt.Println("UUID tuple replace")
46+
fmt.Println("Error", err)
47+
fmt.Println("Code", resp.Code)
48+
fmt.Println("Data", resp.Data)
49+
50+
// Output:
51+
// UUID tuple replace
52+
// Error <nil>
53+
// Code 0
54+
// Data [[c8f0fa1f-da29-438c-a040-393f1126ad39]]
55+
}

0 commit comments

Comments
 (0)