コード例 #1
0
ファイル: item.go プロジェクト: nalin-humin/goamz
func (t *Table) getItem(key *Key, consistentRead bool) (map[string]*Attribute, error) {
	q := NewQuery(t)
	q.AddKey(key)

	if consistentRead {
		q.SetConsistentRead(consistentRead)
	}

	jsonResponse, err := t.Server.queryServer(target("GetItem"), q)
	if err != nil {
		return nil, err
	}

	json, err := simplejson.NewJson(jsonResponse)
	if err != nil {
		return nil, err
	}

	itemJson, ok := json.CheckGet("Item")
	if !ok {
		// We got an empty from amz. The item doesn't exist.
		return nil, ErrNotFound
	}

	item, err := itemJson.Map()
	if err != nil {
		message := fmt.Sprintf("Unexpected response %s", jsonResponse)
		return nil, errors.New(message)
	}

	return parseAttributes(item), nil
}
コード例 #2
0
ファイル: table.go プロジェクト: docker/goamz
func (s *Server) ListTablesCallbackIterator(cb func(string)) error {
	var lastEvaluatedTableName string

	for {
		query := NewEmptyQuery()
		query.AddExclusiveStartTableName(lastEvaluatedTableName)

		jsonResponse, err := s.queryServer(target("ListTables"), query)
		if err != nil {
			return err
		}

		json, err := simplejson.NewJson(jsonResponse)
		if err != nil {
			return err
		}

		lastEvaluatedTableName = ""
		if json, ok := json.CheckGet("LastEvaluatedTableName"); ok {
			lastEvaluatedTableName, err = json.String()
			if err != nil {
				message := fmt.Sprintf("Unexpected response %s", jsonResponse)
				return errors.New(message)
			}
		}

		response, err := json.Get("TableNames").Array()
		if err != nil {
			message := fmt.Sprintf("Unexpected response %s", jsonResponse)
			return errors.New(message)
		}

		for _, value := range response {
			if t, ok := (value).(string); ok {
				cb(t)
			}
		}
		if lastEvaluatedTableName == "" {
			break
		}
	}

	return nil

}