コード例 #1
0
ファイル: backups.go プロジェクト: sethjback/gobl
func modifyBackup(w http.ResponseWriter, r *http.Request) (*httpapi.APIResponse, error) {
	body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
	if err != nil {
		return nil, httpapi.NewError("", "Request too large", 413)
	}

	if err := r.Body.Close(); err != nil {
		return nil, errors.New("")
	}

	backup := new(spec.BackupDefinition)

	err = json.Unmarshal(body, &backup)
	if err != nil {
		return nil, httpapi.NewError(err.Error(), "Invalid backup definition provided", 400)
	}

	vars := mux.Vars(r)

	bID, err := strconv.ParseInt(vars["backupID"], 10, 64)
	if err != nil {
		return nil, httpapi.NewError(err.Error(), "Invalid backup ID", 400)
	}

	backup.ID = int(bID)

	err = manager.ModifyBackup(backup)
	if err != nil {
		return nil, httpapi.NewError(err.Error(), "Unable to modify backup", 400)
	}

	return &httpapi.APIResponse{HTTPCode: 200}, nil
}
コード例 #2
0
ファイル: backupDefinitions.go プロジェクト: sethjback/gobl
// AddBackupDefinition inserts a backup definition into the database
func (d *SQLite) AddBackupDefinition(b *spec.BackupDefinition) error {
	sql := "INSERT INTO " + definitionsTable + " (paramiters, agent) values (?, ?)"

	params, err := json.Marshal(b.Paramiters)
	if err != nil {
		return err
	}

	result, err := d.Connection.Exec(sql, params, b.AgentID)
	if err != nil {
		return err
	}

	id, err := result.LastInsertId()
	if err != nil {
		return err
	}

	b.ID = int(id)

	return nil
}