增加info获取接口

This commit is contained in:
algotao
2025-08-09 22:09:10 +08:00
parent edb12c3b1f
commit 80a758f1e3
7 changed files with 429 additions and 192 deletions

518
cmd.pb.go

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,8 @@ option go_package = "e.coding.net/rta/public/saasapi";
// SaasReq 命令请求
message SaasReq {
oneof cmd {
Info info = 5; // 获取账号设置
Read read = 10; // 批量读取
Write write = 11; // 批量写入
ColumnWrite column_write = 12; // 全量列式写入
@@ -26,6 +28,11 @@ message SaasReq {
}
}
// Info 获取账号信息
message Info {
}
// Read 批量读取命令
message Read {
string dataspace_id = 1; // 数据空间ID
@@ -174,6 +181,8 @@ message SaasRes {
ErrorCode code = 1; // 返回码
string status = 2; // 返回信息的文本提示
oneof res {
InfoRes info_res = 5; // 账号信息返回
ReadRes read_res = 10; // 读取命令返回
WriteRes write_res = 11; // 写入命令返回
@@ -190,6 +199,13 @@ message SaasRes {
}
}
// InfoRes 账号信息返回
message InfoRes {
repeated string dataspace_id = 1; // 可用数据区
repeated string target_id = 2; // 策略ID
}
// ReadRes 读记录返回
message ReadRes {
uint32 succ_cmd_count = 1; // 成功的命令数量

View File

@@ -15,6 +15,7 @@ const usage = `
Usage: saastool COMMAND [OPTIONS]
Commands:
info Saas Info
write Write user's 'bytes / uint32s / flags'
read Read user's 'bytes / uint32s / flags'
columnwrite Write columns for 'deviceid / openid' users

71
cmd/saastool/info.go Normal file
View File

@@ -0,0 +1,71 @@
package main
import (
"flag"
"fmt"
"net/http"
"os"
"e.coding.net/rta/public/saasapi"
"e.coding.net/rta/public/saasapi/pkg/saashttp"
"google.golang.org/protobuf/encoding/protojson"
)
type infoParams struct {
saasHttp *saashttp.SaasClient
}
func RunInfo(args ...string) error {
fs := flag.NewFlagSet("info", flag.ExitOnError)
cfgFile := paramConfig(fs)
if err := fs.Parse(args); err != nil {
fmt.Fprintln(os.Stderr, "command line parse error", "err", err)
return err
}
if fs.NArg() > 0 {
fs.PrintDefaults()
return nil
}
cfg, err := LoadConfigFile(*cfgFile)
if err != nil {
fmt.Fprintln(os.Stderr, "LoadConfigFile error", "err", err)
return err
}
infoParams := infoParams{
saasHttp: &saashttp.SaasClient{
Client: &http.Client{},
ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls),
Auth: &cfg.Auth,
},
}
return doInfo(infoParams)
}
func doInfo(infoParams infoParams) error {
saasReq := &saasapi.SaasReq{
Cmd: &saasapi.SaasReq_Info{
Info: &saasapi.Info{},
},
}
res, err := infoParams.saasHttp.Info(saasReq)
if err != nil {
fmt.Fprintln(os.Stderr, "submit Info error", "err", err)
return err
}
if res.Code != saasapi.ErrorCode_SUCC {
fmt.Fprintln(os.Stderr, "info failed", "code", res.Code, "status", res.Status)
return nil
}
infoRes := res.GetInfoRes()
fmt.Printf("info res: %v\n", protojson.Format(infoRes))
return nil
}

View File

@@ -18,6 +18,8 @@ func Run(args ...string) error {
switch name {
case "", "help":
return RunHelp(args...)
case "info":
return RunInfo(args...)
case "write":
return RunWrite(args...)
case "read":

View File

@@ -2,6 +2,7 @@ package saashttp
const (
baseUrl = "https://api.rta.qq.com"
infoPath = "/saas/info"
writePath = "/saas/write"
readPath = "/saas/read"
columnWritePath = "/saas/column_write"
@@ -20,6 +21,7 @@ const (
type ApiUrls struct {
BaseUrl string
InfoPath string
WritePath string
ReadPath string
ColumnWritePath string
@@ -43,6 +45,12 @@ func InitAPIUrl(c *ApiUrls) *ApiUrls {
r.BaseUrl = baseUrl
}
if c.InfoPath != "" {
r.InfoPath = c.InfoPath
} else {
r.InfoPath = infoPath
}
if c.WritePath != "" {
r.WritePath = c.WritePath
} else {

View File

@@ -33,6 +33,11 @@ type SaasClient struct {
ResponseEncoder ResponseEncoder
}
func (c *SaasClient) Info(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) {
postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.InfoPath)
return c.post(postUrl, saasReq)
}
func (c *SaasClient) Write(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) {
postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.WritePath)
return c.post(postUrl, saasReq)