-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync_result.go
63 lines (51 loc) · 1.36 KB
/
async_result.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package zhipu
import (
"context"
"github.com/go-resty/resty/v2"
)
// AsyncResultService creates a new async result get service
type AsyncResultService struct {
client *Client
id string
}
// AsyncResultVideo is the video result of the AsyncResultService
type AsyncResultVideo struct {
URL string `json:"url"`
CoverImageURL string `json:"cover_image_url"`
}
// AsyncResultResponse is the response of the AsyncResultService
type AsyncResultResponse struct {
Model string `json:"model"`
TaskStatus string `json:"task_status"`
RequestID string `json:"request_id"`
ID string `json:"id"`
VideoResult []AsyncResultVideo `json:"video_result"`
}
// NewAsyncResultService creates a new async result get service
func NewAsyncResultService(client *Client) *AsyncResultService {
return &AsyncResultService{
client: client,
}
}
// SetID sets the id parameter
func (s *AsyncResultService) SetID(id string) *AsyncResultService {
s.id = id
return s
}
func (s *AsyncResultService) Do(ctx context.Context) (res AsyncResultResponse, err error) {
var (
resp *resty.Response
apiError APIErrorResponse
)
if resp, err = s.client.request(ctx).
SetResult(&res).
SetError(&apiError).
Get("async-result/" + s.id); err != nil {
return
}
if resp.IsError() {
err = apiError
return
}
return
}