-
Notifications
You must be signed in to change notification settings - Fork 0
/
slots.go
41 lines (36 loc) · 866 Bytes
/
slots.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
package slots
import (
"context"
"encoding/json"
"io"
"net/http"
"github.com/asia-loop-gmbh/asia-loop-utils-go/v5/pkg/servicewoo"
"github.com/nam-truong-le/lambda-utils-go/v3/pkg/logger"
)
func GetSlots(ctx context.Context) (*Slots, error) {
log := logger.FromContext(ctx)
log.Info("get slots")
serviceWoo, err := servicewoo.NewWoo(ctx)
if err != nil {
return nil, err
}
response, err := http.Get(serviceWoo.NewURLAsiaLoop(ctx, "/delivery-slots"))
if err != nil {
return nil, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Warnf("failed to close response body: %s", err)
}
}(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
slots := new(Slots)
if err := json.Unmarshal(responseBody, slots); err != nil {
return nil, err
}
return slots, nil
}