package client import ( "github.com/edindazdarevic/confighub/chub/globals" "encoding/json" "net/http" "bytes" ) func Init(machine *Machine) bool { machineByteContent, err := json.Marshal(machine) if err != nil { 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 }