github.com/smugmug/godynamo@v0.0.0-20151122084750-7913028f6623/tests/put_item-livetest.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/smugmug/godynamo/conf" 6 "github.com/smugmug/godynamo/conf_file" 7 conf_iam "github.com/smugmug/godynamo/conf_iam" 8 put "github.com/smugmug/godynamo/endpoints/put_item" 9 keepalive "github.com/smugmug/godynamo/keepalive" 10 "github.com/smugmug/godynamo/types/attributevalue" 11 "log" 12 "net/http" 13 "time" 14 ) 15 16 func main() { 17 conf_file.Read() 18 conf.Vals.ConfLock.RLock() 19 if conf.Vals.Initialized == false { 20 panic("the conf.Vals global conf struct has not been initialized") 21 } 22 23 // launch a background poller to keep conns to aws alive 24 if conf.Vals.Network.DynamoDB.KeepAlive { 25 log.Printf("launching background keepalive") 26 go keepalive.KeepAlive([]string{}) 27 } 28 29 // deal with iam, or not 30 if conf.Vals.UseIAM { 31 iam_ready_chan := make(chan bool) 32 go conf_iam.GoIAM(iam_ready_chan) 33 _ = <-iam_ready_chan 34 } 35 conf.Vals.ConfLock.RUnlock() 36 37 put1 := put.NewPutItem() 38 put1.TableName = "test-godynamo-livetest" 39 k := fmt.Sprintf("hk1") 40 v := fmt.Sprintf("%v", time.Now().Unix()) 41 // In simple cases you don't need to call NewAttributeValue 42 put1.Item["TheHashKey"] = &attributevalue.AttributeValue{S: k} 43 put1.Item["TheRangeKey"] = &attributevalue.AttributeValue{N: v} 44 n := fmt.Sprintf("%v", time.Now().Unix()) 45 put1.Item["Mtime"] = &attributevalue.AttributeValue{N: n} 46 put1.Item["SomeJunk"] = &attributevalue.AttributeValue{S: "some junk"} 47 // for complex attributevalue instances, call the constructor first 48 av := attributevalue.NewAttributeValue() 49 av.InsertSS("some junk1") 50 av.InsertSS("some junk2") 51 put1.Item["SomeJunks"] = av 52 av2 := attributevalue.NewAttributeValue() 53 av2.InsertL(&attributevalue.AttributeValue{S: "some junk1"}) 54 av2.InsertL(&attributevalue.AttributeValue{S: "some junk2"}) 55 put1.Item["JunkL"] = av2 56 av3 := attributevalue.NewAttributeValue() 57 av3.InsertM("somejunkkey", &attributevalue.AttributeValue{S: "some junk1"}) 58 59 body, code, err := put1.EndpointReq() 60 if err != nil || code != http.StatusOK { 61 fmt.Printf("put failed %d %v %s\n", code, err, body) 62 } 63 fmt.Printf("%v\n%v\n,%v\n", string(body), code, err) 64 }