-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun.go
More file actions
52 lines (44 loc) · 1.15 KB
/
Copy pathrun.go
File metadata and controls
52 lines (44 loc) · 1.15 KB
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
package scalingo
import (
"context"
"net/http"
"strings"
httpclient "github.com/Scalingo/go-scalingo/v11/http"
"github.com/Scalingo/go-utils/errors/v3"
)
type RunsService interface {
Run(ctx context.Context, opts RunOpts) (*RunRes, error)
}
var _ RunsService = (*Client)(nil)
type RunOpts struct {
App string
Command []string
Env map[string]string
Size string
Detached bool
HasUploads bool
}
type RunRes struct {
Container *Container `json:"container"`
AttachURL string `json:"attach_url"`
OperationURL string `json:"operation_url"`
}
func (c *Client) Run(ctx context.Context, opts RunOpts) (*RunRes, error) {
var runRes RunRes
req := &httpclient.APIRequest{
Method: http.MethodPost,
Endpoint: "/apps/" + opts.App + "/run",
Params: map[string]any{
"command": strings.Join(opts.Command, " "),
"env": opts.Env,
"size": opts.Size,
"detached": opts.Detached,
"has_uploads": opts.HasUploads,
},
}
err := c.ScalingoAPI().DoRequest(ctx, req, &runRes)
if err != nil {
return nil, errors.Wrapf(ctx, err, "request endpoint %v", req.Endpoint)
}
return &runRes, nil
}