first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

View File

@ -0,0 +1,118 @@
package main
import (
"flag"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
)
// LTAI5tCB8SmJcwfO
// dX4kgF4VcblsbCVdKvtCGCmvNbLkZK
// ./AliyunCloudClient -t b -o update -key LTAI5tCB8SmJcwfO -sec dX4kgF4VcblsbCVdKvtCGCmvNbLkZK -reg cn-hangzhou -lb "[{"ServerId":"ServerId","Weight":"0"}]
func main() {
var target string
flag.StringVar(&target, "t", "b", "target: b=backendServer")
var operation string
flag.StringVar(&operation, "o", "update", "operation: add、update、remove")
var accessKeyId string
flag.StringVar(&accessKeyId, "key", "accessKeyId", "accessKeyId")
var accessSecret string
flag.StringVar(&accessSecret, "sec", "accessSecret", "accessSecret")
var regionId string
flag.StringVar(&regionId, "reg", "regionId", "regionId: cn-hangzhou")
var loadBalancerId string
flag.StringVar(&loadBalancerId, "lb", "loadBalancerId", "loadBalancerId")
var params string
flag.StringVar(&params, "params", "", `SetBackendServers: [{"ServerId":"ServerId","Weight":"0"}]
AddBackendServers: [{"ServerId":"ServerId","Weight":"100","Type":"eni","ServerIp":"192.168.11.1"}]
RemoveBackendServers: [{"ServerId":"ServerId","Weight":"100"}]
`)
flag.Parse()
flag.Usage()
fmt.Printf("target=%s,operation=%s,accessKeyId=%s,accessSecret=%s,regionId=%s,loadBalancerId=%s,params=%s", target, operation, accessKeyId, accessSecret, regionId, loadBalancerId, params)
if target == "b" {
switch operation {
case "update":
SetBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
break
case "add":
AddBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
break
case "remove":
RemoveBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
break
default:
fmt.Println("operation: " + operation + " not support")
}
} else {
fmt.Println("target: " + target + " not support")
}
}
func SetBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
// client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
// if nil != err {
// fmt.Println("get client error:")
// fmt.Println(err.Error())
// }
// request := slb.CreateSetBackendServersRequest()
// request.Scheme = "https"
// request.LoadBalancerId = loadBalancerId
// request.BackendServers = params
// if nil == client {
// fmt.Println("error: client is nil")
// return
// }
// response, err := client.SetBackendServers(request)
// if err != nil {
// fmt.Print(err.Error())
// }
// fmt.Printf("response is %#v\n", response)
}
func AddBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
request := slb.CreateAddBackendServersRequest()
request.Scheme = "https"
request.LoadBalancerId = loadBalancerId
request.BackendServers = params
if nil == client {
fmt.Println("error: client is nil")
return
}
response, err := client.AddBackendServers(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}
func RemoveBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
request := slb.CreateRemoveBackendServersRequest()
request.Scheme = "https"
request.LoadBalancerId = loadBalancerId
request.BackendServers = params
if nil == client {
fmt.Println("error: client is nil")
return
}
response, err := client.RemoveBackendServers(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}

View File

@ -0,0 +1,70 @@
package main
import (
"encoding/json"
"fmt"
"strconv"
"github.com/tealeg/xlsx"
)
func main02() {
data := ReadSheet("./CmdTools/星钻VIP体系.xlsx", 0)
fmt.Println(json.Marshal(data))
for index, item := range data {
if index > 0 {
level, _ := strconv.Atoi(item[0])
exp, _ := strconv.Atoi(item[1])
fmt.Printf("insert into t_vip_config (id,vip_level,min_exp,vip_name,vip_icon,create_time) values (%d,%d,%d,'v%d','https://xz-static.10909.com/XingZuanCommon/Img/Vip/%d@2x.png',now());\n", level, level, exp, level, level)
}
}
}
func ReadSheet(file string, sheet int) [][]string {
var result [][]string
xlFile, err := xlsx.OpenFile(file)
if err != nil {
fmt.Println(err.Error())
return result
}
for index, row := range xlFile.Sheets[sheet].Rows {
if index > 60 {
break
}
var data []string
for index, cell := range row.Cells {
if index > 1 {
break
}
text := cell.String()
println(text)
data = append(data, text)
}
result = append(result, data)
}
return result
}
func ReadAll(file string) {
// 打开文件
xlFile, err := xlsx.OpenFile(file)
if err != nil {
fmt.Println(err.Error())
return
}
// 遍历sheet页读取
for _, sheet := range xlFile.Sheets {
fmt.Println("sheet name: ", sheet.Name)
//遍历行读取
for _, row := range sheet.Rows {
// 遍历每行的列读取
for _, cell := range row.Cells {
text := cell.String()
fmt.Printf("%20s", text)
}
fmt.Print("\n")
}
}
fmt.Println("\n\nimport success")
}

View File

@ -0,0 +1,94 @@
package main
import (
"flag"
"fmt"
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
)
// ./TencentCloudClient -t b -o add -key AKIDSoxxjI5tukPr9ECsQmwthKhroaCZlldI -sec b1FG2b3JMrESVLxjJdhYDgx12qPiplXB -reg ap-shanghai -params "{\"LoadBalancerId\":\"lb-jip7505r\",\"Targets\":[{\"InstanceId\":\"ins-n2i7x483\",\"Weight\":20}]}"
// ./TencentCloudClient -t b -o remove -key AKIDSoxxjI5tukPr9ECsQmwthKhroaCZlldI -sec b1FG2b3JMrESVLxjJdhYDgx12qPiplXB -reg ap-shanghai -params "{\"LoadBalancerId\":\"lb-jip7505r\",\"InstanceIds\":[\"ins-n2i7x483\"]}"
func main03() {
var target string
flag.StringVar(&target, "t", "b", "target: b=backendServer")
var operation string
flag.StringVar(&operation, "o", "add", "operation: add、remove")
var accessKeyId string
flag.StringVar(&accessKeyId, "key", "secretId", "accessKeyId")
var accessSecret string
flag.StringVar(&accessSecret, "sec", "secretKey", "accessSecret")
var regionId string
flag.StringVar(&regionId, "reg", "regionId", "regionId: cn-hangzhou")
var params string
flag.StringVar(&params, "params", "params", `
AddBackendServers: [{"ServerId":"ServerId","Weight":"100","Type":"eni","ServerIp":"192.168.11.1"}]
RemoveBackendServers: [{"ServerId":"ServerId","Weight":"100"}]
`)
flag.Parse()
flag.Usage()
fmt.Printf("target=%s,operation=%s,accessKeyId=%s,accessSecret=%s,regionId=%s,params=%s\n", target, operation, accessKeyId, accessSecret, regionId, params)
if target == "b" {
switch operation {
case "add":
ClassicBind(regionId, accessKeyId, accessSecret, params)
break
case "remove":
ClassicRemove(regionId, accessKeyId, accessSecret, params)
break
default:
fmt.Println("operation: " + operation + " not support")
}
} else {
fmt.Println("target: " + target + " not support")
}
}
func ClassicBind(regionId, accessKeyId, accessSecret, params string) {
credential := common.NewCredential(accessKeyId, accessSecret)
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "clb.tencentcloudapi.com"
client, _ := clb.NewClient(credential, regionId, cpf)
request := clb.NewRegisterTargetsWithClassicalLBRequest()
err := request.FromJsonString(params)
if err != nil {
panic(err)
}
response, err := client.RegisterTargetsWithClassicalLB(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}
fmt.Printf("%s", response.ToJsonString())
}
func ClassicRemove(regionId, accessKeyId, accessSecret, params string) {
credential := common.NewCredential(accessKeyId, accessSecret)
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "clb.tencentcloudapi.com"
client, _ := clb.NewClient(credential, regionId, cpf)
request := clb.NewDeregisterTargetsFromClassicalLBRequest()
err := request.FromJsonString(params)
if err != nil {
panic(err)
}
response, err := client.DeregisterTargetsFromClassicalLB(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}
fmt.Printf("%s", response.ToJsonString())
}

View File

@ -0,0 +1,57 @@
# CMD 工具
## 阿里云SLB后端服务器client工具
### Usage
Example: SlbClient.exe -t lb -o update -reg cn-hangzhou -key LTAI5tCB8SmJcwfO -sec dX4kgF4VcblsbCVdKvtCGCmvNbLkZK -lb lb-bp1nz8xl5q8kiqfv0iumf -params "[{\"ServerId\":\"i-bp1hcv8qx0677hv9pr0s\",\"Weight\":\"100\"}]"
```
Usage of SlbClient.exe:
-key string
accessKeyId (default "accessKeyId")
-lb string
loadBalancerId (default "loadBalancerId")
-o string
operation: add、update、remove (default "update")
-params string
SetBackendServers: [{"ServerId":"ServerId","Weight":"0"}]
AddBackendServers: [{"ServerId":"ServerId","Weight":"100","Type":"eni","ServerIp":"192.168.11.1"}]
RemoveBackendServers: [{"ServerId":"ServerId","Weight":"100"}]
(default "params")
-reg string
regionId: cn-hangzhou (default "regionId")
-sec string
accessSecret (default "accessSecret")
-t string
target: lb (default "lb")
```
## 腾讯云CLB后端服务器client工具
### Usage
Example1 ./TencentCloudClient -t b -o add -key AKIDSoxxjI5tukPr9ECsQmwthKhroaCZlldI -sec b1FG2b3JMrESVLxjJdhYDgx12qPiplXB -reg ap-shanghai -params "{\"LoadBalancerId\":\"lb-jip7505r\",\"Targets\":[{\"InstanceId\":\"ins-n2i7x483\",\"Weight\":20}]}"
Example2 ./TencentCloudClient -t b -o remove -key AKIDSoxxjI5tukPr9ECsQmwthKhroaCZlldI -sec b1FG2b3JMrESVLxjJdhYDgx12qPiplXB -reg ap-shanghai -params "{\"LoadBalancerId\":\"lb-jip7505r\",\"InstanceIds\":[\"ins-n2i7x483\"]}"
```
Usage of ./TencentCloudClient:
-key string
accessKeyId (default "secretId")
-o string
operation: add、remove (default "add")
-params string
AddBackendServers: [{"ServerId":"ServerId","Weight":"100","Type":"eni","ServerIp":"192.168.11.1"}]
RemoveBackendServers: [{"ServerId":"ServerId","Weight":"100"}]
(default "params")
-reg string
regionId: cn-hangzhou (default "regionId")
-sec string
accessSecret (default "secretKey")
-t string
target: b=backendServer (default "b")
```