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 listExpParams struct { saasHttp *saashttp.SaasClient } func RunExpList(args ...string) error { fs := flag.NewFlagSet("list", 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) } listExpParams := listExpParams{ saasHttp: &saashttp.SaasClient{ Client: &http.Client{}, ApiUrls: saashttp.InitAPIUrl(&cfg.ApiUrls), Auth: &cfg.Auth, }, } return doExpList(listExpParams) } func doExpList(listExpParams listExpParams) error { saasReq := &saasapi.SaasReq{ Cmd: &saasapi.SaasReq_ExpList{ ExpList: &saasapi.ExpList{}, }, } res, err := listExpParams.saasHttp.ExpList(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) } listExpRes := res.GetExpListRes() fmt.Printf("exp res: %v\n", protojson.Format(listExpRes)) return nil }