This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdyno.go
120 lines (100 loc) · 3.44 KB
/
dyno.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// WARNING: This code is auto-generated from the Heroku Platform API JSON Schema
// by a Ruby script (gen/gen.rb). Changes should be made to the generation
// script rather than the generated files.
package heroku
import (
"time"
)
// Dynos encapsulate running processes of an app on Heroku.
type Dyno struct {
// a URL to stream output from for attached processes or null for non-attached processes
AttachURL *string `json:"attach_url"`
// command used to start this process
Command string `json:"command"`
// when dyno was created
CreatedAt time.Time `json:"created_at"`
// unique identifier of this dyno
Id string `json:"id"`
// the name of this process on this dyno
Name string `json:"name"`
// app release of the dyno
Release struct {
Id string `json:"id"`
Version int `json:"version"`
} `json:"release"`
// dyno size (default: "1X")
Size string `json:"size"`
// current status of process (either: crashed, down, idle, starting, or up)
State string `json:"state"`
// type of process
Type string `json:"type"`
// when process last changed state
UpdatedAt time.Time `json:"updated_at"`
}
// Create a new dyno.
//
// appIdentity is the unique identifier of the Dyno's App. command is the
// command used to start this process. options is the struct of optional
// parameters for this action.
func (c *Client) DynoCreate(appIdentity string, command string, options *DynoCreateOpts) (*Dyno, error) {
params := struct {
Command string `json:"command"`
Attach *bool `json:"attach,omitempty"`
Env *map[string]string `json:"env,omitempty"`
Size *string `json:"size,omitempty"`
}{
Command: command,
}
if options != nil {
params.Attach = options.Attach
params.Env = options.Env
params.Size = options.Size
}
var dynoRes Dyno
return &dynoRes, c.Post(&dynoRes, "/apps/"+appIdentity+"/dynos", params)
}
// DynoCreateOpts holds the optional parameters for DynoCreate
type DynoCreateOpts struct {
// whether to stream output or not
Attach *bool `json:"attach,omitempty"`
// custom environment to add to the dyno config vars
Env *map[string]string `json:"env,omitempty"`
// dyno size (default: "1X")
Size *string `json:"size,omitempty"`
}
// Restart dyno.
//
// appIdentity is the unique identifier of the Dyno's App. dynoIdentity is the
// unique identifier of the Dyno.
func (c *Client) DynoRestart(appIdentity string, dynoIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/dynos/" + dynoIdentity)
}
// Restart all dynos
//
// appIdentity is the unique identifier of the Dyno's App.
func (c *Client) DynoRestartAll(appIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/dynos")
}
// Info for existing dyno.
//
// appIdentity is the unique identifier of the Dyno's App. dynoIdentity is the
// unique identifier of the Dyno.
func (c *Client) DynoInfo(appIdentity string, dynoIdentity string) (*Dyno, error) {
var dyno Dyno
return &dyno, c.Get(&dyno, "/apps/"+appIdentity+"/dynos/"+dynoIdentity)
}
// List existing dynos.
//
// appIdentity is the unique identifier of the Dyno's App. lr is an optional
// ListRange that sets the Range options for the paginated list of results.
func (c *Client) DynoList(appIdentity string, lr *ListRange) ([]Dyno, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/dynos", nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var dynosRes []Dyno
return dynosRes, c.DoReq(req, &dynosRes)
}