working POSTbody()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-28 20:02:05 +00:00
parent 2b7a5fa43d
commit 34351697e3
2 changed files with 35 additions and 7 deletions

BIN
goclient/.client.go.swp Normal file

Binary file not shown.

View File

@ -54,12 +54,13 @@ func main() {
ge := pb.MakeOkResponse()
c := pb.MakeDefaultConfig()
ge.Account = c.Accounts[0]
ge.Account.Username = "jcarr@wit.com"
ge.Account.Email = "jcarr@wit.com"
ge.Account.Password = "yowzayowza"
// ge.Account.Token = "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e"
ge.Account.URL = "http://stackapi:4000/"
ge.Account.Token = "badtoken"
checkLogin(ge)
junkEvent := processLoginEvent(ge)
log.Println("processAddEvent() junkEvent =", junkEvent)
log.Println("processAddEvent() START ge.Account =", ge.Account)
@ -69,11 +70,10 @@ func main() {
tmp = string(GETbody(ge, "http://stackapi:4000/clusters"))
log.Println("processAddEvent() recieved json=", tmp)
// stackapi:4000/vms/jcarr.com?count=1&cpu=2&ram=512&disk=25
url := ge.Account.URL + "vms/jcarr.com?count=1&cpu=2&ram=512&disk=25"
json := newFetchBody(ge, "POST", url)
log.Println("processAddEvent() recieved json=", json)
tmp = string(POSTbody(ge, url))
log.Println("processAddEvent() recieved json=", tmp)
}
@ -284,3 +284,31 @@ func GETbody(ge *pb.Event, URL string) string {
}
return string(body)
}
func POSTbody(ge *pb.Event, URL string) string {
// req, err := http.NewRequest("GET", ge.Account.URL + "clusters", nil)
log.Println("POSTbody() url =", URL)
req, err := http.NewRequest("POST", URL, nil)
if err != nil {
log.Println("POSTbody() can't make new req")
return ""
}
req.Header.Set("X-Wit-Auth", ge.Account.Token)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("Can't exec the req to list networks: %s", err)
return ""
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("can't read resp")
return ""
}
// log.Printf("GETbody() body =", string(body))
if body == nil {
log.Println("networks is nil")
return ""
}
return string(body)
}