-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuilds.go
More file actions
63 lines (50 loc) · 1.4 KB
/
builds.go
File metadata and controls
63 lines (50 loc) · 1.4 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
53
54
55
56
57
58
59
60
61
62
63
// Package builds provides methods for managing app builds.
package builds
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// Get a build of an app.
func Get(c *drycc.Client, appID string, version int) (api.Build, error) {
u := fmt.Sprintf("/v2/apps/%s/build/", appID)
if version > 0 {
u = fmt.Sprintf("%s?version=v%d", u, version)
}
res, reqErr := c.Request("GET", u, nil)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return api.Build{}, reqErr
}
defer res.Body.Close()
var build api.Build
if err := json.NewDecoder(res.Body).Decode(&build); err != nil {
return api.Build{}, err
}
return build, reqErr
}
// New a build of an app.
func New(c *drycc.Client, appID string, image string, stack string,
procfile map[string]string, dryccfile map[string]interface{}) (api.Build, error) {
u := fmt.Sprintf("/v2/apps/%s/build/", appID)
req := api.CreateBuildRequest{
Image: image,
Stack: stack,
Procfile: procfile,
Dryccfile: dryccfile,
}
body, err := json.Marshal(req)
if err != nil {
return api.Build{}, err
}
res, reqErr := c.Request("POST", u, body)
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
return api.Build{}, reqErr
}
defer res.Body.Close()
build := api.Build{}
if err = json.NewDecoder(res.Body).Decode(&build); err != nil {
return api.Build{}, err
}
return build, reqErr
}