-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwrap.go
32 lines (26 loc) · 996 Bytes
/
wrap.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
package whalewall
import (
"context"
"time"
"github.com/docker/docker/api/types"
)
// wrappedDockerClient is a Docker client that respects the set timeout.
type wrappedDockerClient struct {
timeout time.Duration
dockerClient
}
func (w *wrappedDockerClient) Ping(ctx context.Context) (types.Ping, error) {
return withTimeout(ctx, w.timeout, func(ctx context.Context) (types.Ping, error) {
return w.dockerClient.Ping(ctx)
})
}
func (w *wrappedDockerClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
return withTimeout(ctx, w.timeout, func(ctx context.Context) ([]types.Container, error) {
return w.dockerClient.ContainerList(ctx, options)
})
}
func (w *wrappedDockerClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) {
return withTimeout(ctx, w.timeout, func(ctx context.Context) (types.ContainerJSON, error) {
return w.dockerClient.ContainerInspect(ctx, containerID)
})
}