https://github.com/radekg/yugabyte-db-go-client
YugabyteDB client for golang
https://github.com/radekg/yugabyte-db-go-client
cli client-library golang yugabytedb
Last synced: 5 months ago
JSON representation
YugabyteDB client for golang
- Host: GitHub
- URL: https://github.com/radekg/yugabyte-db-go-client
- Owner: radekg
- License: apache-2.0
- Created: 2021-08-22T23:41:32.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-22T17:58:16.000Z (over 4 years ago)
- Last Synced: 2024-06-21T20:58:31.482Z (about 2 years ago)
- Topics: cli, client-library, golang, yugabytedb
- Language: Go
- Homepage:
- Size: 633 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YugabyteDB client for go
Work in progress. Current state: it does what it says it does.
## Go client
### Usage
```go
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/hashicorp/go-hclog"
"github.com/radekg/yugabyte-db-go-client/client"
"github.com/radekg/yugabyte-db-go-client/configs"
"github.com/radekg/yugabyte-db-go-client/errors"
ybApi "github.com/radekg/yugabyte-db-go-proto/v2/yb/api"
)
func main() {
// construct the configuration:
cfg := &configs.YBClientConfig{
MasterHostPort: []string{"127.0.0.1:7100", "127.0.0.1:17000", "127.0.0.1:27000"},
OpTimeout: time.Duration(time.Second * 5),
}
customLogger := hclog.Default()
client := client.NewYBClient(cfg).
WithLogger(customLogger.Named("custom-client-logger"))
if err := client.Connect(); err != nil {
panic(err)
}
request := &ybApi.ListMastersRequestPB{}
response := &ybApi.ListMastersResponsePB{}
err := client.Execute(request, response)
if err != nil {
client.Close()
logger.Error("failed executing the request", "reason", err)
panic(err)
}
// some of the payloads provide their own error responses,
// handle it like this:
if err := response.GetError(); err != nil {
client.Close()
logger.Error("request returned an error", "reason", err)
panic(err)
}
// do something with the result:
bytes, err := json.MarshalIndent(response, "", " ")
if err != nil {
client.Close()
logger.Error("failed marshalling the response as JSON", "reason", err)
panic(err)
}
fmt.Println("successful masters response", string(bytes))
// close the client at the very end
client.Close()
}
```
## Versions
Notes on the client versions:
- YugabyteDB `2.13.0+`: use client version `v0.0.2-beta.2`
- YugabyteDB `2.11.2`: use client version `v0.0.2-beta.1`
- YugabyteDB `2.9.x`, `2.11.0`, `2.11.1`: use client version `v0.0.1-beta.4`