66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.algo.com.cn/public/saasapi"
|
|
"git.algo.com.cn/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 {
|
|
return fmt.Errorf("Command line parse error: %w", err)
|
|
}
|
|
|
|
if fs.NArg() > 0 {
|
|
fs.PrintDefaults()
|
|
return nil
|
|
}
|
|
|
|
cfg, err := LoadConfigFile(*cfgFile)
|
|
if err != nil {
|
|
return fmt.Errorf("LoadConfigFile error: %w", 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 {
|
|
return fmt.Errorf("Submit Command error: %w", err)
|
|
}
|
|
|
|
if res.Code != saasapi.ErrorCode_SUCC {
|
|
return fmt.Errorf("Command failed. code:%v, status:%v", res.Code, res.Status)
|
|
}
|
|
|
|
infoRes := res.GetInfoRes()
|
|
|
|
fmt.Printf("Info res: %v\n", protojson.Format(infoRes))
|
|
return nil
|
|
}
|