in entryMaker/oneCRL/oneCRL.go [373:408]
func AddKintoObject(url string, obj interface{}) error {
conf := config.GetConfig()
marshalled, _ := json.Marshal(obj)
if conf.Preview != "yes" {
if "yes" == conf.OneCRLVerbose {
fmt.Printf("Will POST to \"%s\" with \"%s\"\n", url+"/records", marshalled)
}
req, err := http.NewRequest("POST", url+"/records", bytes.NewBuffer(marshalled))
if len(conf.KintoToken) > 0 {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", conf.KintoToken))
} else if len(conf.KintoUser) > 0 {
req.SetBasicAuth(conf.KintoUser, conf.KintoPassword)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if nil != err {
panic(err)
}
err = checkResponseStatus(resp, "There was a problem adding a record")
defer resp.Body.Close()
if nil != err {
return err
}
} else {
fmt.Printf("Would POST to \"%s\" with \"%s\"\n", url+"/records", marshalled)
}
return nil
}