Last active
November 11, 2015 07:58
-
-
Save takeshiyako2/06cae06532b4c19f8c1b to your computer and use it in GitHub Desktop.
GoDynamo sample of simple put/get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/smugmug/godynamo/conf" | |
"github.com/smugmug/godynamo/conf_file" | |
get "github.com/smugmug/godynamo/endpoints/get_item" | |
"github.com/smugmug/godynamo/types/attributevalue" | |
"net/http" | |
) | |
func main() { | |
// Read GoDynamo AWS config file | |
conf_file.Read() | |
conf.Vals.ConfLock.RLock() | |
if conf.Vals.Initialized == false { | |
panic("the conf.Vals global conf struct has not been initialized") | |
} | |
conf.Vals.ConfLock.RUnlock() | |
// Get items | |
get1 := get.NewGetItem() | |
get1.TableName = "bbpd-test" | |
get1.Key["user_id"] = &attributevalue.AttributeValue{S: "my-user-id"} | |
body, code, err := get1.EndpointReq() | |
if err != nil || code != http.StatusOK { | |
fmt.Printf("get failed %d %v %s\n", code, err, body) | |
} | |
fmt.Printf("%v\n%v\n,%v\n", string(body), code, err) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/smugmug/godynamo/conf" | |
"github.com/smugmug/godynamo/conf_file" | |
put "github.com/smugmug/godynamo/endpoints/put_item" | |
"github.com/smugmug/godynamo/types/attributevalue" | |
"net/http" | |
"time" | |
) | |
func main() { | |
// Read GoDynamo AWS config file | |
conf_file.Read() | |
conf.Vals.ConfLock.RLock() | |
if conf.Vals.Initialized == false { | |
panic("the conf.Vals global conf struct has not been initialized") | |
} | |
conf.Vals.ConfLock.RUnlock() | |
// Make item data | |
put1 := put.NewPutItem() | |
put1.TableName = "bbpd-test" | |
// Set data with attributevalue | |
timestamp := fmt.Sprintf("%v", time.Now().Unix()) | |
put1.Item["user_id"] = &attributevalue.AttributeValue{S: "my-user-id"} | |
put1.Item["timestamp"] = &attributevalue.AttributeValue{N: timestamp} | |
// Send the request | |
body, code, err := put1.EndpointReq() | |
if err != nil || code != http.StatusOK { | |
fmt.Printf("put1 failed %d %v %s\n", code, err, body) | |
} | |
fmt.Printf("%v\n%v\n,%v\n", string(body), code, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment