-
Notifications
You must be signed in to change notification settings - Fork 8
/
wait.go
50 lines (46 loc) · 1.5 KB
/
wait.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
package bucket
import (
"context"
"net/http"
"github.com/SchwarzIT/community-stackit-go-client/pkg/services/object-storage/v1.0.1/bucket"
"github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
"github.com/SchwarzIT/community-stackit-go-client/pkg/wait"
)
// Wait waits for creation. in case there are no errors, the returned interface is of *GetResponse
func (*CreateResponse) WaitHandler(ctx context.Context, c *bucket.ClientWithResponses, projectID, bucketName string) *wait.Handler {
return wait.New(func() (interface{}, bool, error) {
res, err := c.Get(ctx, projectID, bucketName)
if err = validate.Response(res, err); err != nil {
if validate.StatusEquals(res,
http.StatusBadGateway,
http.StatusGatewayTimeout,
http.StatusInternalServerError,
http.StatusNotFound,
) {
return nil, false, nil
}
return nil, false, err
}
return res, true, nil
})
}
// Wait waits for deletion
func (*DeleteResponse) WaitHandler(ctx context.Context, c *bucket.ClientWithResponses, projectID, bucketName string) *wait.Handler {
return wait.New(func() (interface{}, bool, error) {
res, err := c.Get(ctx, projectID, bucketName)
if err = validate.Response(res, err); err != nil {
if validate.StatusEquals(res, http.StatusNotFound) {
return nil, true, nil
}
if validate.StatusEquals(res,
http.StatusBadGateway,
http.StatusGatewayTimeout,
http.StatusInternalServerError,
) {
return nil, false, nil
}
return nil, false, err
}
return nil, false, nil
})
}