12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package client
- import (
- "encoding/json"
- "fmt"
- "net/url"
- "strconv"
- )
- const (
- createDataContainerUrl = "/ds/api/v1/dataContainer/create"
- deleteDataContainerUrl = "/ds/api/v1/dataContainer/delete"
- getDataContainersUrl = "/ds/api/v1/dataContainer/query"
- )
- func (c *Client) CreateDataContainer(token string, baseUrl string, namespace string, dataSource string, name string, spec map[string]any) error {
- fullUrl, err := url.JoinPath(baseUrl, createDataContainerUrl)
- if err != nil {
- return err
- }
- resp := new(MsgResponse)
- specJsonBytes, err := json.Marshal(spec)
- if err != nil {
- return err
- }
- err = c.post(token, fullUrl, map[string]any{
- "namespace": namespace,
- "dataSource": dataSource,
- "name": name,
- "spec": string(specJsonBytes),
- }, resp)
- if err != nil {
- return err
- }
- if !resp.Success {
- return fmt.Errorf(resp.Msg)
- }
- return nil
- }
- func (c *Client) DeleteDataContainer(token string, baseUrl string, namespace string, dataSource string, name string) error {
- fullUrl, err := url.JoinPath(baseUrl, deleteDataContainerUrl)
- if err != nil {
- return err
- }
- resp := new(MsgResponse)
- err = c.post(token, fullUrl, map[string]any{
- "namespace": namespace,
- "dataSource": dataSource,
- "name": name,
- }, resp)
- if err != nil {
- return err
- }
- if !resp.Success {
- return fmt.Errorf(resp.Msg)
- }
- return nil
- }
- func (c *Client) GetDataContainers(token string, baseUrl string, namespace string, dataSource string, name string, pageNo int, pageSize int) ([]DataContainerInfo, error) {
- fullUrl, err := url.JoinPath(baseUrl, getDataContainersUrl)
- if err != nil {
- return nil, err
- }
- resp := new(InfosResponse[DataContainerInfo])
- err = c.get(token, fullUrl, map[string]string{
- "namespace": namespace,
- "dataSource": dataSource,
- "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
- }
|