You need to enable JavaScript to run this app.
导航
初始化客户端
最近更新时间:2024.02.06 15:13:32首次发布时间:2023.11.21 16:38:02

veDB MySQL Go SDK 支持通过 Session 的方式初始化客户端。通过 Session 方式创建的 veDB MySQL 客户端,底层会实现 HTTP/HTTPS 资源(连接或请求)的复用。当需要初始化多个客户端进行操作时,通过 Session 方式创建可以提升客户端的性能。本文介绍如何通过 Session 方式初始化客户端。

前提条件

初始化客户端

使用如下代码初始化客户端。

import (
    "github.com/volcengine/volcengine-go-sdk/volcengine"
    "github.com/volcengine/volcengine-go-sdk/volcengine/credentials"
    "github.com/volcengine/volcengine-go-sdk/volcengine/session"
    "github.com/volcengine/volcengine-go-sdk/service/vedbm"
)

var (
    region      string
    ak          string
    sk          string
    config      *volcengine.Config
    sess        *session.Session
    VeDBMClient *VEDBM
)

func InitClient() {
    region = "your region"
    ak = "your ak"
    sk = "your sk"
    config = volcengine.NewConfig().
       WithCredentials(credentials.NewStaticCredentials(ak, sk, "")).
       WithRegion(region).
       WithEndpoint("service host")
    sess, _ = session.NewSession(config)
    VeDBMClient = New(sess)
}