data_source.go 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package client
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strconv"
  6. )
  7. const (
  8. getDataSourcesUrl = "/ds/api/v1/dataSource/query"
  9. )
  10. func (c *Client) GetDataSources(token string, baseUrl string, namespace string, name string, typeStr string, pageNo int, pageSize int) ([]DataSourceInfo, error) {
  11. fullUrl, err := url.JoinPath(baseUrl, getDataSourcesUrl)
  12. if err != nil {
  13. return nil, err
  14. }
  15. resp := new(struct {
  16. Success bool `json:"success"`
  17. Msg string `json:"msg"`
  18. Infos []DataSourceInfo `json:"infos"`
  19. TotalCount int64 `json:"totalCount"`
  20. PageNo int64 `json:"pageNo"`
  21. })
  22. err = c.get(token, fullUrl, map[string]string{
  23. "namespace": namespace,
  24. "name": name,
  25. "type": typeStr,
  26. "pageNo": strconv.Itoa(pageNo),
  27. "pageSize": strconv.Itoa(pageSize),
  28. }, resp)
  29. if err != nil {
  30. return nil, err
  31. }
  32. if !resp.Success {
  33. return nil, fmt.Errorf(resp.Msg)
  34. }
  35. return resp.Infos, nil
  36. }