-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_file_content.go
46 lines (40 loc) · 1.24 KB
/
get_file_content.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
package clients
import (
models "cf-html5-apps-repo-cli-plugin/clients/models"
"cf-html5-apps-repo-cli-plugin/log"
"io/ioutil"
"net/http"
)
// GetFileContent get HTML5 applications file content
func GetFileContent(serviceURL string, filePath string, accessToken string, appHostGUID string, resultChannel chan<- models.HTML5ApplicationFileContent) {
var request *http.Request
var response *http.Response
var err error
var html5URL string
var body = make([]byte, 0)
html5URL = serviceURL + filePath
log.Tracef("Making request to: %s\n", html5URL)
client := &http.Client{}
request, err = http.NewRequest("GET", html5URL, nil)
if err != nil {
resultChannel <- models.HTML5ApplicationFileContent{Error: err}
return
}
request.Header.Add("Authorization", "Bearer "+accessToken)
if appHostGUID != "" {
request.Header.Add("x-app-host-id", appHostGUID)
}
response, err = client.Do(request)
if err != nil {
resultChannel <- models.HTML5ApplicationFileContent{Error: err}
return
}
// Get response body
defer response.Body.Close()
body, err = ioutil.ReadAll(response.Body)
if err != nil {
resultChannel <- models.HTML5ApplicationFileContent{Error: err}
return
}
resultChannel <- models.HTML5ApplicationFileContent{Content: body}
}