-
Notifications
You must be signed in to change notification settings - Fork 8
/
container.go
60 lines (50 loc) · 1.7 KB
/
container.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
package scalingo
import (
"context"
"fmt"
"time"
"gopkg.in/errgo.v1"
httpclient "github.com/Scalingo/go-scalingo/v7/http"
)
type ContainersService interface {
ContainersStop(ctx context.Context, appName, containerID string) error
}
var _ ContainersService = (*Client)(nil)
type Container struct {
ID string `json:"id"`
AppID string `json:"app_id"`
CreatedAt *time.Time `json:"created_at"`
DeletedAt *time.Time `json:"deleted_at"`
Command string `json:"command"`
Type string `json:"type"`
TypeIndex int `json:"type_index"`
Label string `json:"label"`
State string `json:"state"`
App *App `json:"app"`
ContainerSize ContainerSize `json:"container_size"`
}
func (c *Client) ContainersStop(ctx context.Context, appName, containerID string) error {
req := &httpclient.APIRequest{
Method: "POST",
Endpoint: fmt.Sprintf("/apps/%s/containers/%s/stop", appName, containerID),
Expected: httpclient.Statuses{202},
}
err := c.ScalingoAPI().DoRequest(ctx, req, nil)
if err != nil {
return errgo.Notef(err, "fail to execute the POST request to stop a container")
}
return nil
}
func (c *Client) ContainersKill(ctx context.Context, app string, signal string, containerID string) error {
req := &httpclient.APIRequest{
Method: "POST",
Endpoint: "/apps/" + app + "/containers/" + containerID + "/kill",
Params: map[string]interface{}{"signal": signal},
Expected: httpclient.Statuses{204},
}
err := c.ScalingoAPI().DoRequest(ctx, req, nil)
if err != nil {
return errgo.Notef(err, "fail to execute the POST request to send signal to a container")
}
return nil
}