package client import ( "fmt" "net/url" "strconv" ) const ( generateTokenUrl = "/ds/api/admin/token/generate" deleteTokenUrl = "/ds/api/admin/token/delete" getTokensUrl = "/ds/api/admin/token/query" ) func (c *Client) GenerateToken(token string, baseUrl string, name string) (string, error) { fullUrl, err := url.JoinPath(baseUrl, generateTokenUrl) if err != nil { return "", err } resp := new(struct { MsgResponse Token string `json:"token"` }) 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 resp.Token, nil } func (c *Client) DeleteToken(token string, baseUrl string, name string) error { fullUrl, err := url.JoinPath(baseUrl, deleteTokenUrl) 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) GetTokens(token string, baseUrl string, name string, pageNo int, pageSize int) ([]TokenInfo, error) { fullUrl, err := url.JoinPath(baseUrl, getTokensUrl) if err != nil { return nil, err } resp := new(InfosResponse[TokenInfo]) 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 }