-
Notifications
You must be signed in to change notification settings - Fork 0
/
management.go
30 lines (28 loc) · 865 Bytes
/
management.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package vanceai
import (
"context"
"fmt"
"net/http"
)
func (cli *Client) GetPoint(ctx context.Context) (Response, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cli.BaseURL.String()+"/point", nil)
if err != nil {
return Response{}, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
q := req.URL.Query()
q.Add("api_token", cli.APIKey)
req.URL.RawQuery = q.Encode()
resStruct := Response{}
resp, err := cli.doAndUnmarshal(ctx, req, &resStruct)
if err != nil {
return Response{}, fmt.Errorf("failed to do request: %w", err)
}
if resp.StatusCode != http.StatusOK {
return Response{}, fmt.Errorf("failed to get point: %s", resp.Status)
}
if err := resStruct.Error(); err != nil {
return Response{}, fmt.Errorf("failed to get point: %w", err)
}
return resStruct, nil
}