github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/tests/query-param-conf-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  	ep "github.com/smugmug/godynamo/endpoint"
     9  	query "github.com/smugmug/godynamo/endpoints/query"
    10  	"github.com/smugmug/godynamo/types/attributevalue"
    11  	"github.com/smugmug/godynamo/types/condition"
    12  	"net/http"
    13  	"os"
    14  )
    15  
    16  func main() {
    17  
    18  	home := os.Getenv("HOME")
    19  	home_conf_file := home + string(os.PathSeparator) + "." + conf.CONF_NAME
    20  	home_conf, home_conf_err := conf_file.ReadConfFile(home_conf_file)
    21  	if home_conf_err != nil {
    22  		panic("cannot read conf from " + home_conf_file)
    23  	}
    24  	home_conf.ConfLock.RLock()
    25  	if home_conf.Initialized == false {
    26  		panic("conf struct has not been initialized")
    27  	}
    28  
    29  	tn := "test-godynamo-livetest"
    30  	q := query.NewQuery()
    31  	q.TableName = tn
    32  	q.Select = ep.SELECT_ALL
    33  	k_v1 := fmt.Sprintf("AHashKey%d", 100)
    34  	kc := condition.NewCondition()
    35  	kc.AttributeValueList = make([]*attributevalue.AttributeValue, 1)
    36  	kc.AttributeValueList[0] = &attributevalue.AttributeValue{S: k_v1}
    37  	kc.ComparisonOperator = query.OP_EQ
    38  	q.Limit = 10000
    39  	q.KeyConditions["TheHashKey"] = kc
    40  	json, _ := json.Marshal(q)
    41  	fmt.Printf("JSON:%s\n", string(json))
    42  	body, code, err := q.EndpointReqWithConf(home_conf)
    43  	if err != nil || code != http.StatusOK {
    44  		fmt.Printf("query failed %d %v %s\n", code, err, body)
    45  	}
    46  	fmt.Printf("%v\n%v\n%v\n", string(body), code, err)
    47  }