github.com/naphatkrit/deis@v1.12.3/client/controller/models/builds/builds.go (about) 1 package builds 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/deis/deis/client/controller/api" 8 "github.com/deis/deis/client/controller/client" 9 ) 10 11 // List lists an app's builds. 12 func List(c *client.Client, appID string, results int) ([]api.Build, int, error) { 13 u := fmt.Sprintf("/v1/apps/%s/builds/", appID) 14 body, count, err := c.LimitedRequest(u, results) 15 16 if err != nil { 17 return []api.Build{}, -1, err 18 } 19 20 var builds []api.Build 21 if err = json.Unmarshal([]byte(body), &builds); err != nil { 22 return []api.Build{}, -1, err 23 } 24 25 return builds, count, nil 26 } 27 28 // New creates a build for an app. 29 func New(c *client.Client, appID string, image string, 30 procfile map[string]string) (api.Build, error) { 31 32 u := fmt.Sprintf("/v1/apps/%s/builds/", appID) 33 34 req := api.CreateBuildRequest{Image: image, Procfile: procfile} 35 36 body, err := json.Marshal(req) 37 38 if err != nil { 39 return api.Build{}, err 40 } 41 42 resBody, err := c.BasicRequest("POST", u, body) 43 44 if err != nil { 45 return api.Build{}, err 46 } 47 48 build := api.Build{} 49 if err = json.Unmarshal([]byte(resBody), &build); err != nil { 50 return api.Build{}, err 51 } 52 53 return build, nil 54 }