123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package client
- import (
- "fmt"
- "net/url"
- "strconv"
- )
- const (
- createNamespaceUrl = "/ds/api/v1/namespace/create"
- deleteNamespaceUrl = "/ds/api/v1/namespace/delete"
- getNamespacesUrl = "/ds/api/v1/namespace/query"
- )
- func (c *Client) CreateNamespace(token string, baseUrl string, name string) error {
- fullUrl, err := url.JoinPath(baseUrl, createNamespaceUrl)
- if err != nil {
- return err
- }
- resp := new(MsgResponse)
- err = c.post(token, fullUrl, map[string]any{
- "name": name,
- }, resp)
- if err != nil {
- return err
- }
- if !resp.Success {
- return fmt.Errorf(resp.Msg)
- }
- return nil
- }
- func (c *Client) DeleteNamespace(token string, baseUrl string, name string) error {
- fullUrl, err := url.JoinPath(baseUrl, deleteNamespaceUrl)
- if err != nil {
- return err
- }
- resp := new(MsgResponse)
- err = c.post(token, fullUrl, map[string]any{
- "name": name,
- }, resp)
- if err != nil {
- return err
- }
- if !resp.Success {
- return fmt.Errorf(resp.Msg)
- }
- return nil
- }
- func (c *Client) GetNamespaces(token string, baseUrl string, name string, pageNo int, pageSize int) ([]NamespaceInfo, error) {
- fullUrl, err := url.JoinPath(baseUrl, getNamespacesUrl)
- if err != nil {
- return nil, err
- }
- resp := new(InfosResponse[NamespaceInfo])
- err = c.get(token, fullUrl, map[string]string{
- "name": name,
- "pageNo": strconv.Itoa(pageNo),
- "pageSize": strconv.Itoa(pageSize),
- }, resp)
- if err != nil {
- return nil, err
- }
- if !resp.Success {
- return nil, fmt.Errorf(resp.Msg)
- }
- return resp.Infos, nil
- }
|