@@ -29,13 +29,18 @@ type Environment struct {
29
29
UpdatedAt time.Time `json:"updated_at" tab:"-"`
30
30
LastOpenedAt time.Time `json:"last_opened_at" tab:"-"`
31
31
LastConnectionAt time.Time `json:"last_connection_at" tab:"-"`
32
- AutoOffThreshold xjson.Duration `json:"auto_off_threshold" tab:"-"`
32
+ AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" tab:"-"`
33
33
}
34
34
35
35
// RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed.
36
36
type RebuildMessage struct {
37
- Text string `json:"text"`
38
- Required bool `json:"required"`
37
+ Text string `json:"text"`
38
+ Required bool `json:"required"`
39
+ AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" tab:"-"`
40
+ RebuildMessages []struct {
41
+ Text string `json:"text"`
42
+ Required bool `json:"required"`
43
+ } `json:"rebuild_messages" tab:"-"`
39
44
}
40
45
41
46
// EnvironmentStat represents the state of an environment
@@ -51,9 +56,7 @@ type EnvironmentStat struct {
51
56
DiskUsed int64 `json:"disk_used"`
52
57
}
53
58
54
- func (e EnvironmentStat ) String () string {
55
- return string (e .ContainerStatus )
56
- }
59
+ func (e EnvironmentStat ) String () string { return string (e .ContainerStatus ) }
57
60
58
61
// EnvironmentStatus refers to the states of an environment.
59
62
type EnvironmentStatus string
@@ -67,7 +70,7 @@ const (
67
70
EnvironmentUnknown EnvironmentStatus = "UNKNOWN"
68
71
)
69
72
70
- // CreateEnvironmentRequest is used to configure a new environment
73
+ // CreateEnvironmentRequest is used to configure a new environment.
71
74
type CreateEnvironmentRequest struct {
72
75
Name string `json:"name"`
73
76
ImageID string `json:"image_id"`
@@ -81,50 +84,39 @@ type CreateEnvironmentRequest struct {
81
84
82
85
// CreateEnvironment sends a request to create an environment.
83
86
func (c Client ) CreateEnvironment (ctx context.Context , orgID string , req CreateEnvironmentRequest ) (* Environment , error ) {
84
- var env * Environment
85
- err := c .requestBody (
86
- ctx ,
87
- http .MethodPost , "/api/orgs/" + orgID + "/environments" ,
88
- req ,
89
- env ,
90
- )
91
- return env , err
87
+ var env Environment
88
+ if err := c .requestBody (ctx , http .MethodPost , "/api/orgs/" + orgID + "/environments" , req , & env ); err != nil {
89
+ return nil , err
90
+ }
91
+ return & env , nil
92
92
}
93
93
94
94
// EnvironmentsByOrganization gets the list of environments owned by the given user.
95
95
func (c Client ) EnvironmentsByOrganization (ctx context.Context , userID , orgID string ) ([]Environment , error ) {
96
96
var envs []Environment
97
- err := c .requestBody (
98
- ctx ,
99
- http .MethodGet , "/api/orgs/" + orgID + "/members/" + userID + "/environments" ,
100
- nil ,
101
- & envs ,
102
- )
103
- return envs , err
97
+ if err := c .requestBody (ctx , http .MethodGet , "/api/orgs/" + orgID + "/members/" + userID + "/environments" , nil , & envs ); err != nil {
98
+ return nil , err
99
+ }
100
+ return envs , nil
104
101
}
105
102
106
103
// DeleteEnvironment deletes the environment.
107
104
func (c Client ) DeleteEnvironment (ctx context.Context , envID string ) error {
108
- return c .requestBody (
109
- ctx ,
110
- http .MethodDelete , "/api/environments/" + envID ,
111
- nil ,
112
- nil ,
113
- )
105
+ return c .requestBody (ctx , http .MethodDelete , "/api/environments/" + envID , nil , nil )
114
106
}
115
107
116
108
// DialWsep dials an environments command execution interface
117
- // See github.com/cdr/wsep for details
109
+ // See https:// github.com/cdr/wsep for details.
118
110
func (c Client ) DialWsep (ctx context.Context , env * Environment ) (* websocket.Conn , error ) {
119
- return c .dialWs (ctx , "/proxy/environments/" + env .ID + "/wsep" )
111
+ return c .dialWebsocket (ctx , "/proxy/environments/" + env .ID + "/wsep" )
120
112
}
121
113
122
- // DialEnvironmentBuildLog opens a websocket connection for the environment build log messages
114
+ // DialEnvironmentBuildLog opens a websocket connection for the environment build log messages.
123
115
func (c Client ) DialEnvironmentBuildLog (ctx context.Context , envID string ) (* websocket.Conn , error ) {
124
- return c .dialWs (ctx , "/api/environments/" + envID + "/watch-update" )
116
+ return c .dialWebsocket (ctx , "/api/environments/" + envID + "/watch-update" )
125
117
}
126
118
127
- // DialEnvironmentStats opens a websocket connection for environment stats
119
+ // DialEnvironmentStats opens a websocket connection for environment stats.
128
120
func (c Client ) DialEnvironmentStats (ctx context.Context , envID string ) (* websocket.Conn , error ) {
129
- return c .dialWs (ctx , "/api/environments/" + envID + "/watch-stats" )
121
+ return c .dialWebsocket (ctx , "/api/environments/" + envID + "/watch-stats" )
130
122
}
0 commit comments