Beispiel #1
0
// Given a record allow settings to be updated.
func updateRecord(d *diskv.Diskv, name string) error {
	var h Host
	val, err := d.Read(md5sum(name))
	if err != nil {
		return fmt.Errorf("no configuration found for %s\n", name)
	}

	err = json.Unmarshal(val, &h)
	if err != nil {
		return fmt.Errorf("failed to parse the configuration: %s\n", err.Error())
	}

	err = h.updateConfig()
	if err != nil {
		return fmt.Errorf("failed to update the host information: %s", err.Error())
	}

	val, err = json.Marshal(h)
	if err != nil {
		return err
	}

	d.Write(md5sum(name), []byte(val))

	return nil
}
Beispiel #2
0
// Create the configuration record and store it in the datastore
func addRecord(d *diskv.Diskv, name, hostInfo string) error {
	h := Host{Nickname: name, KeepAlive: 30}
	var err error

	if hostInfo == "" {
		err = h.interactiveConfig()
		if err != nil {
			return err
		}
	} else {
		info := strings.Split(hostInfo, ":")
		err = h.config(info)
		if err != nil {
			return err
		}
	}

	val, err := json.Marshal(h)
	if err != nil {
		return err
	}

	d.Write(md5sum(name), []byte(val))
	return nil
}