namespace.go 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package client
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strconv"
  6. )
  7. const (
  8. getNamespacesUrl = "/ds/api/v1/namespace/query"
  9. )
  10. func (c *Client) GetNamespaces(token string, baseUrl string, name string, pageNo int, pageSize int) ([]NamespaceInfo, error) {
  11. fullUrl, err := url.JoinPath(baseUrl, getNamespacesUrl)
  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 []NamespaceInfo `json:"infos"`
  19. TotalCount int64 `json:"totalCount"`
  20. PageNo int64 `json:"pageNo"`
  21. })
  22. err = c.get(token, fullUrl, map[string]string{
  23. "name": name,
  24. "pageNo": strconv.Itoa(pageNo),
  25. "pageSize": strconv.Itoa(pageSize),
  26. }, resp)
  27. if err != nil {
  28. return nil, err
  29. }
  30. if !resp.Success {
  31. return nil, fmt.Errorf(resp.Msg)
  32. }
  33. return resp.Infos, nil
  34. }