finished init command - it now initialises the stuff
This commit is contained in:
@@ -1,14 +1,34 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"github.com/edindazdarevic/confighub/chub/globals"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
func Init(machine *Machine) {
|
||||
req, err := http.NewRequest("POST", url, nil)
|
||||
func Init(machine *Machine) bool {
|
||||
|
||||
machineByteContent, err := json.Marshal(machine)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
globals.PanicWithStyle("I am so ashamed. But something happened that just should not happen. :~(",err)
|
||||
}
|
||||
|
||||
resourceUrl := globals.UrlOfTheService + "machine"
|
||||
req, err := http.NewRequest("POST", resourceUrl, bytes.NewBuffer(machineByteContent))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
response, err := client.Do(req)
|
||||
if err != nil {
|
||||
globals.PanicWithStyle("Ah. I cannot get to the server to init your machine. Are you sure you have connection to internet ?",err)
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
globals.PanicWithStyle("Something is wrong on our end. Ask us about it on twitter, facebook, email, phone - you can even fax as. Smoke signals will not work. ", err)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user