示例#1
0
// UpdateRecord updated a record from the parameters specified and
// returns an error if it fails.
func (c *Client) UpdateRecord(domainID string, recordID string, cr map[string]interface{}) (string, error) {

	current, err := c.ReadRecord(domainID, recordID)
	if err != nil {
		return "", err
	}

	err = mergo.Map(current, cr)
	if err != nil {
		return "", err
	}

	buf := bytes.NewBuffer(nil)
	enc := json.NewEncoder(buf)
	if err := enc.Encode(current); err != nil {
		return "", err
	}

	path := update.endpoint(domainID, recordID)
	req, err := c.NewRequest("PUT", path, buf, "")
	if err != nil {
		return "", err
	}

	_, err = checkResp(c.HTTP.Do(req))
	if err != nil {
		return "", fmt.Errorf("Error updating record: %s", err)
	}

	// The request was successful
	return recordID, nil
}
示例#2
0
文件: where.go 项目: angdev/chocolat
func (this *Where) Visit(v *Visitor) {
	match := make(RawExpr)

	for _, cond := range this.Conditions {
		mergo.Map(&match, cond.RawExpr())
	}

	v.Collect(Stage{
		"$match": match,
	})
}
示例#3
0
func (ex *ExifProc) UPDATEMeta(file_path string, datum StandartJSON) error {
	// exiftool -json=a.json a.png -overwrite_original
	ex.Busy = true
	// ====== MERGE MAPS ======
	old_meta := ex.GETMeta(file_path).Items
	new_corpus := datum
	var old_corpus StandartJSON
	if len(old_meta) > 0 {
		old_corpus = old_meta[0]
	} else {
		ex.Busy = false
		return errors.New("No suitable corpus for file")
	}
	mergo.Map(&new_corpus, old_corpus)
	// ====== WRITE JSON ======
	new_corpus_byte, err := json.Marshal(new_corpus)
	if err != nil {
		ex.Busy = false
		return err
	}
	// in case there is no temp dir
	err = os.MkdirAll(TEMP_DIR, 0777)
	if err != nil {
		ex.Busy = false
		return err
	}

	// ====== CREATE TEMP JSON FILE =====
	json_path := path.Join(TEMP_DIR, uuid.NewV4().String()+".json")

	err = ioutil.WriteFile(json_path, new_corpus_byte, 0644)
	if err != nil {
		ex.Busy = false
		return err
	}
	// ====== POST DATUM FOR WORKAGE =====
	// exiftool -json=a.json a.png -overwrite_original

	ex.stdin <- fmt.Sprintf("%s\n-json=%s\n-overwrite_original\n-execute\n", file_path, json_path)
	msg := <-ex.stdout
	log.Println(msg)
	// ====== DELETE STALE FILE ====
	err = os.Remove(json_path)
	if err != nil {
		ex.Busy = false
		return err
	}
	ex.Busy = false
	return nil
}