增加info获取接口
This commit is contained in:
16
cmd.proto
16
cmd.proto
@@ -7,6 +7,8 @@ option go_package = "e.coding.net/rta/public/saasapi";
|
|||||||
// SaasReq 命令请求
|
// SaasReq 命令请求
|
||||||
message SaasReq {
|
message SaasReq {
|
||||||
oneof cmd {
|
oneof cmd {
|
||||||
|
Info info = 5; // 获取账号设置
|
||||||
|
|
||||||
Read read = 10; // 批量读取
|
Read read = 10; // 批量读取
|
||||||
Write write = 11; // 批量写入
|
Write write = 11; // 批量写入
|
||||||
ColumnWrite column_write = 12; // 全量列式写入
|
ColumnWrite column_write = 12; // 全量列式写入
|
||||||
@@ -26,6 +28,11 @@ message SaasReq {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Info 获取账号信息
|
||||||
|
message Info {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Read 批量读取命令
|
// Read 批量读取命令
|
||||||
message Read {
|
message Read {
|
||||||
string dataspace_id = 1; // 数据空间ID
|
string dataspace_id = 1; // 数据空间ID
|
||||||
@@ -174,6 +181,8 @@ message SaasRes {
|
|||||||
ErrorCode code = 1; // 返回码
|
ErrorCode code = 1; // 返回码
|
||||||
string status = 2; // 返回信息的文本提示
|
string status = 2; // 返回信息的文本提示
|
||||||
oneof res {
|
oneof res {
|
||||||
|
InfoRes info_res = 5; // 账号信息返回
|
||||||
|
|
||||||
ReadRes read_res = 10; // 读取命令返回
|
ReadRes read_res = 10; // 读取命令返回
|
||||||
WriteRes write_res = 11; // 写入命令返回
|
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 读记录返回
|
// ReadRes 读记录返回
|
||||||
message ReadRes {
|
message ReadRes {
|
||||||
uint32 succ_cmd_count = 1; // 成功的命令数量
|
uint32 succ_cmd_count = 1; // 成功的命令数量
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const usage = `
|
|||||||
Usage: saastool COMMAND [OPTIONS]
|
Usage: saastool COMMAND [OPTIONS]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
info Saas Info
|
||||||
write Write user's 'bytes / uint32s / flags'
|
write Write user's 'bytes / uint32s / flags'
|
||||||
read Read user's 'bytes / uint32s / flags'
|
read Read user's 'bytes / uint32s / flags'
|
||||||
columnwrite Write columns for 'deviceid / openid' users
|
columnwrite Write columns for 'deviceid / openid' users
|
||||||
|
|||||||
71
cmd/saastool/info.go
Normal file
71
cmd/saastool/info.go
Normal 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
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@ func Run(args ...string) error {
|
|||||||
switch name {
|
switch name {
|
||||||
case "", "help":
|
case "", "help":
|
||||||
return RunHelp(args...)
|
return RunHelp(args...)
|
||||||
|
case "info":
|
||||||
|
return RunInfo(args...)
|
||||||
case "write":
|
case "write":
|
||||||
return RunWrite(args...)
|
return RunWrite(args...)
|
||||||
case "read":
|
case "read":
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package saashttp
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
baseUrl = "https://api.rta.qq.com"
|
baseUrl = "https://api.rta.qq.com"
|
||||||
|
infoPath = "/saas/info"
|
||||||
writePath = "/saas/write"
|
writePath = "/saas/write"
|
||||||
readPath = "/saas/read"
|
readPath = "/saas/read"
|
||||||
columnWritePath = "/saas/column_write"
|
columnWritePath = "/saas/column_write"
|
||||||
@@ -20,6 +21,7 @@ const (
|
|||||||
|
|
||||||
type ApiUrls struct {
|
type ApiUrls struct {
|
||||||
BaseUrl string
|
BaseUrl string
|
||||||
|
InfoPath string
|
||||||
WritePath string
|
WritePath string
|
||||||
ReadPath string
|
ReadPath string
|
||||||
ColumnWritePath string
|
ColumnWritePath string
|
||||||
@@ -43,6 +45,12 @@ func InitAPIUrl(c *ApiUrls) *ApiUrls {
|
|||||||
r.BaseUrl = baseUrl
|
r.BaseUrl = baseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.InfoPath != "" {
|
||||||
|
r.InfoPath = c.InfoPath
|
||||||
|
} else {
|
||||||
|
r.InfoPath = infoPath
|
||||||
|
}
|
||||||
|
|
||||||
if c.WritePath != "" {
|
if c.WritePath != "" {
|
||||||
r.WritePath = c.WritePath
|
r.WritePath = c.WritePath
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ type SaasClient struct {
|
|||||||
ResponseEncoder ResponseEncoder
|
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) {
|
func (c *SaasClient) Write(saasReq *saasapi.SaasReq) (saasRes *saasapi.SaasRes, err error) {
|
||||||
postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.WritePath)
|
postUrl := c.makeUrl(c.ApiUrls.BaseUrl, c.ApiUrls.WritePath)
|
||||||
return c.post(postUrl, saasReq)
|
return c.post(postUrl, saasReq)
|
||||||
|
|||||||
Reference in New Issue
Block a user