-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.go
39 lines (31 loc) · 830 Bytes
/
progress.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
package api
import (
"context"
"encoding/json"
"io"
"time"
"github.com/pkg/errors"
"github.com/wolftotem4/go-dope-ben-don/internal/client"
typesjson "github.com/wolftotem4/go-dope-ben-don/internal/types/json"
)
func CallProgress(ctx context.Context, c client.Client) (*typesjson.Progress, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
res, err := c.Call(ctx, "/mvc/api/order/progress", client.Api)
if err != nil {
return nil, errors.WithStack(err)
}
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errors.WithStack(err)
}
defer res.Body.Close()
var data typesjson.Progress
if err := json.Unmarshal(body, &data); err != nil {
return nil, errors.WithStack(err)
}
if data.Error != "" {
return nil, handleErrorMsg(data.Error)
}
return &data, nil
}