https://github.com/oceanbase/obshell-sdk-go
https://github.com/oceanbase/obshell-sdk-go
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/oceanbase/obshell-sdk-go
- Owner: oceanbase
- License: apache-2.0
- Created: 2024-04-19T05:55:10.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-11T07:03:44.000Z (6 months ago)
- Last Synced: 2025-07-11T10:50:34.490Z (6 months ago)
- Language: Go
- Size: 153 KB
- Stars: 2
- Watchers: 6
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
English | [Chinese](README_CN.md)
**OBShell-SDK-GO** is an SDK provided by the[OceanBase Community](https://open.oceanbase.com/) to facilitate developers with quick access to OBShell services, allowing them to conveniently call OBShell interfaces using this SDK.
## Install
```shell
go get github.com/oceanbase/obshell-sdk-go@master
```
## Quick Start
Please ensure that OBShell is running when using it.
### Create a Client
You can choose to create a single-version client.
``` GO
package main
import (
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
client, err := v1.NewClientWithPassword("11.11.11.1", 2886, "***")
if err != nil {
// Handle error.
return
}
}
```
Or create a multi-version client set.
``` GO
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
clientset, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
if err != nil {
// Handle error.
return
}
}
```
### Deploy Cluster
``` GO
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
client, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
if err != nil {
return
}
joinReqeust1 := client.V1().NewJoinRequest("11.11.11.1", 2886, "zone1")
if _, err := client.V1().JoinSyncWithRequest(joinReqeust1); err != nil {
return
}
joinReqeust2 := client.V1().NewJoinRequest("11.11.11.2", 2886, "zone2")
if _, err := client.V1().JoinSyncWithRequest(joinReqeust2); err != nil {
return
}
joinReqeust3 := client.V1().NewJoinRequest("11.11.11.3", 2886, "zone3")
if _, err := client.V1().JoinSyncWithRequest(joinReqeust3); err != nil {
return
}
// Configure the cluster.
configObclusterReq := client.V1().NewConfigObclusterRequest("obshell-sdk-test", 12358).SetRootPwd("****")
if _, err := client.V1().ConfigObclusterSyncWithRequest(configObclusterReq); err != nil {
return
}
// Configure the observers.
configs := map[string]string{
"datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G",
}
configObserverReq := client.V1().NewConfigObserverRequest(configs, v1.SCOPE_GLOBAL)
if _, err := client.V1().ConfigObserverSyncWithRequest(configObserverReq); err != nil {
return
}
// Initialize the cluster.
initReq := client.V1().NewInitRequest()
if _, err := client.V1().InitSyncWithRequest(initReq); err != nil {
return
}
}
```
### Scale out
``` GO
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
client, err := services.NewClientWithPassword("11.11.11.1", 2886, "****")
if err != nil {
return
}
// OBShell prior to 4.2.3.0 should use mysqlPort(rpcPort) instead of mysql_port(rpc_port).
configs := map[string]string{
"mysql_port": "2881", "rpc_port": "2882", "datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G",
}
// Scale out a new server in zone3.
scaleOutReq := client.V1().NewScaleOutRequest("11.11.11.3", 2886, "zone3", configs)
if _, err := client.V1().ScaleOutSyncWithRequest(scaleOutReq); err != nil {
return
}
}
```