github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/tests/query-livetest.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"github.com/smugmug/godynamo/conf"
     7  	"github.com/smugmug/godynamo/conf_file"
     8  	conf_iam "github.com/smugmug/godynamo/conf_iam"
     9  	ep "github.com/smugmug/godynamo/endpoint"
    10  	query "github.com/smugmug/godynamo/endpoints/query"
    11  	keepalive "github.com/smugmug/godynamo/keepalive"
    12  	"github.com/smugmug/godynamo/types/attributevalue"
    13  	"github.com/smugmug/godynamo/types/condition"
    14  	"log"
    15  	"net/http"
    16  )
    17  
    18  func main() {
    19  	conf_file.Read()
    20  	conf.Vals.ConfLock.RLock()
    21  	if conf.Vals.Initialized == false {
    22  		panic("the conf.Vals global conf struct has not been initialized")
    23  	}
    24  
    25  	// launch a background poller to keep conns to aws alive
    26  	if conf.Vals.Network.DynamoDB.KeepAlive {
    27  		log.Printf("launching background keepalive")
    28  		go keepalive.KeepAlive([]string{})
    29  	}
    30  
    31  	// deal with iam, or not
    32  	if conf.Vals.UseIAM {
    33  		iam_ready_chan := make(chan bool)
    34  		go conf_iam.GoIAM(iam_ready_chan)
    35  		_ = <-iam_ready_chan
    36  	}
    37  	conf.Vals.ConfLock.RUnlock()
    38  
    39  	tn := "test-godynamo-livetest"
    40  	q := query.NewQuery()
    41  	q.TableName = tn
    42  	q.Select = ep.SELECT_ALL
    43  	k_v1 := fmt.Sprintf("AHashKey%d", 100)
    44  	kc := condition.NewCondition()
    45  	kc.AttributeValueList = make([]*attributevalue.AttributeValue, 1)
    46  	kc.AttributeValueList[0] = &attributevalue.AttributeValue{S: k_v1}
    47  	kc.ComparisonOperator = query.OP_EQ
    48  	q.Limit = 10000
    49  	q.KeyConditions["TheHashKey"] = kc
    50  	json, _ := json.Marshal(q)
    51  	fmt.Printf("JSON:%s\n", string(json))
    52  	body, code, err := q.EndpointReq()
    53  	if err != nil || code != http.StatusOK {
    54  		fmt.Printf("query failed %d %v %s\n", code, err, body)
    55  	}
    56  	fmt.Printf("%v\n%v\n%v\n", string(body), code, err)
    57  }