Once you have installed the driver and set up an Ultipa instance, you can connect your application to the database.
You can establish a connection using the configurations from UltipaConfig
. See UltipaConfig Struct.
Creating a Connection
Creates a connection using sdk.NewUltipaDriver()
:
package main
import (
"log"
"github.com/ultipa/ultipa-go-sdk/sdk"
"github.com/ultipa/ultipa-go-sdk/sdk/configuration"
)
func main() {
config := &configuration.UltipaConfig{
// URI example: Hosts: []string{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"},
Hosts: []string{"192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"},
Username: "<usernmae>",
Password: "<password>",
}
driver, err := sdk.NewUltipaDriver(config)
if err != nil {
log.Fatalln("Failed to connect to Ultipa:", err)
}
isSuccess, _ := driver.Test(nil)
println(isSuccess)
}
true
Using Configuration File
This example demonstrates how to use a configuration file (config.yml
) to establish a connection:
package main
import (
"log"
"github.com/ultipa/ultipa-go-sdk/sdk"
"github.com/ultipa/ultipa-go-sdk/sdk/configuration"
)
func main() {
config, _ := configuration.LoadConfigFromYAML("./config.yml")
driver, err := sdk.NewUltipaDriver(config)
if err != nil {
log.Fatalln("Failed to connect to Ultipa:", err)
}
isSuccess, _ := driver.Test(nil)
println(isSuccess)
}
true
Example of the config.yml
file:
hosts:
- "192.168.1.85:60061"
- "192.168.1.87:60061"
- "192.168.1.88:60061"
# URI example
# hosts: ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
username: "<username>"
password: "<password>"
default_graph:
crt:
passwordencrypt:
timeout:
heart_beat:
max_recv_size:
UltipaConfig Struct
The UltipaConfig
struct includes the following fields:
Field |
Type |
Default |
Description |
---|---|---|---|
Hosts |
[]string | / | Required. A comma-separated list of database server IPs or URLs. The protocol is automatically identified, do not include https:// or http:// as a prefix in the URL. |
Username |
string | / | Required. Username of the host authentication. |
Password |
string | / | Required. Password of the host authentication. |
DefaultGraph |
string | / | Name of the graph to use by default in the database. |
Crt |
[]byte | / | The file path of the SSL certificate used for secure connections. |
PasswordEncrypt |
string | MD5 |
Password encryption method of the driver. Supports MD5 , LDAP and NOTHING . |
Timeout |
int32 | Maximum | Request timeout threshold (in seconds). |
Heartbeat |
int | 0 | The heartbeat interval (in milliseconds), used to keep the connection alive. Set to 0 to disable. |
MaxRecvSize |
int | 32 | The maximum size (in MB) of the received data. |