-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_start.go
69 lines (64 loc) · 1.21 KB
/
app_start.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
package main
import (
"bytes"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
func init() {
register(&Command{
group: "Application",
name: "app.start",
help: "Start application",
params: []Param{
Param{name: "name", desc: "Application name"},
Param{name: "space", desc: "Space name"},
Param{name: "org", desc: "Organization name"},
},
handle: app_start,
})
}
func app_start() {
target, err := c.SelectedTarget()
if err != nil {
log.Fatal(err)
}
// Get Application ID
app, err := target.AppFind(params["name"], params["space"], params["org"])
if err != nil {
log.Fatal(err)
}
resp, err := target.AppStart(app.Guid)
if err != nil {
log.Fatal(err)
}
stagingUrl := resp.Header.Get("X-App-Staging-Log")
if stagingUrl != "" {
readStaging(stagingUrl)
}
}
func readStaging(url string) {
written := 0
for {
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
if resp.StatusCode == http.StatusNotFound {
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
if len(body) > written {
io.Copy(os.Stdout, bytes.NewReader(body[written:]))
written = len(body)
}
resp.Body.Close()
<-time.After(1 * time.Second)
}
}