Beispiel #1
0
func (mux *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	guidRequest := &GUIDRequest{}
	d := json.NewDecoder(request.Body)
	if err := d.Decode(&guidRequest); err != nil {
		log.Error("Error decoding JSON: ", err)
		http.Error(writer, err.Error(), 500)
	}

	dynamo := dynamodb.Server{
		Auth:   awsAuth,
		Region: aws.USEast,
	}

	locationsTable := dynamo.NewTable(dynamoTable, pk)

	// lls, err := locationsTable.Scan([]dynamodb.AttributeComparison{
	// 	*dynamodb.NewStringAttributeComparison("hash", dynamodb.COMPARISON_NOT_EQUAL, "asdf"),
	// })
	// for _, ll := range lls {
	// 	log.Info(ll["hash"].Value)
	// }

	digest := sha256.Sum256([]byte(guidRequest.Guid))
	hashKey := hex.EncodeToString(digest[:])
	// item, err := locationsTable.GetItem(&dynamodb.Key{HashKey: hashKey})
	item, err := locationsTable.GetItem(&dynamodb.Key{HashKey: guidRequest.Guid})
	if err != nil {
		log.Error("Error getting item from table: ", err)
	}

	location := &LocationResponse{
		Hash:     hashKey,
		Bucket:   item["bucket"].Value,
		RandLine: item["randLine"].Value,
	}

	if infoLog {
		log.Infof("S3 key: %s", location.Bucket)
	}

	response := GUIDResponse{
		GuidHash:   location.Hash,
		BucketName: location.Bucket,
	}

	jsonResponse, err := json.Marshal(response)
	if err != nil {
		log.Error("Error marshalling JSON: ", err)
	}

	// locations <- location
	go processLog(location)

	writer.Write(jsonResponse)
}
Beispiel #2
0
func testDynamodb() (bool, error) {

	auth, err := aws.GetAuth("test", "test", "test", time.Now())

	if err != nil {
		log.Panic(err)
	}

	ddb := dynamodb.Server{auth, local}

	tables, err := ddb.ListTables()

	if err != nil {
		return false, errors.New("DYNAMODB KO")
	}

	log.Printf("%v\n", tables)
	return true, nil
}