Skip to content

Commit

Permalink
docs: update according to the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
askalt committed Nov 17, 2023
1 parent 75bcdc4 commit 1ed2418
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,22 @@ import (
"context"
"fmt"
"time"

"github.com/tarantool/go-tarantool/v2"
)

func main() {
opts := tarantool.Opts{User: "guest"}
ctx, cancel := context.WithTimeout(context.Background(),
dialer := tarantool.TtDialer {
Address: "127.0.0.1:3301",
User: "guest",
}
opts := tarantool.Opts{
Timeout: time.Second,
}
ctx, cancel := context.WithTimeout(context.Background(),
500 * time.Millisecond)
defer cancel()
conn, err := tarantool.Connect(ctx, "127.0.0.1:3301", opts)
conn, err := tarantool.Connect(ctx, dialer, opts)
if err != nil {
fmt.Println("Connection refused:", err)
}
Expand All @@ -135,34 +141,45 @@ func main() {
**Observation 1:** The line "`github.com/tarantool/go-tarantool/v2`" in the
`import(...)` section brings in all Tarantool-related functions and structures.

**Observation 2:** The line starting with "`Opts :=`" sets up the options for
**Observation 2:** The line starting with "`dialer :=`" creates dialer for
`Connect()`. This structure contains fields required to establish a connection.

**Observation 3:** The line starting with "`opts :=`" sets up the options for
`Connect()`. In this example, the structure contains only a single value, the
username. The structure may also contain other settings, see more in
timeout. The structure may also contain other settings, see more in
[documentation][godoc-opts-url] for the "`Opts`" structure.

**Observation 3:** The line containing "`tarantool.Connect`" is essential for
**Observation 4:** The line containing "`tarantool.Connect`" is essential for
starting a session. There are three parameters:

* a context,
* a string with `host:port` format,
* a dialer that was set up earlier,
* the option structure that was set up earlier.

There will be only one attempt to connect. If multiple attempts needed,
"`tarantool.Connect`" could be placed inside the loop with some timeout
between each try. Example could be found in the [example_test](./example_test.go),
name - `ExampleConnect_reconnects`.

**Observation 4:** The `err` structure will be `nil` if there is no error,
**Observation 5:** The `err` structure will be `nil` if there is no error,
otherwise it will have a description which can be retrieved with `err.Error()`.

**Observation 5:** The `Insert` request, like almost all requests, is preceded
**Observation 6:** The `Insert` request, like almost all requests, is preceded
by the method `Do` of object `conn` which is the object that was returned
by `Connect()`.

### Migration to v2

The article describes migration from go-tarantool to go-tarantool/v2.

#### dialer

Now you need to use `Dialer` for connect to the Tarantool instead of
specifying the address. If you were using a non-SSL connection, you need
to create `TtDialer`. For SSL-enabled connections, use `OpenSslDialer`.
Please note that the options for creating a connection are now stored in
corresponding `Dialer`, not in `Opts`.

#### datetime package

Now you need to use objects of the Datetime type instead of pointers to it. A
Expand Down

0 comments on commit 1ed2418

Please sign in to comment.