本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/simpledb.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleSimpleDB_BatchPutAttributes
func ExampleSimpleDB_BatchPutAttributes() {
svc := simpledb.New(nil)
params := &simpledb.BatchPutAttributesInput{
DomainName: aws.String("String"), // Required
Items: []*simpledb.ReplaceableItem{ // Required
{ // Required
Attributes: []*simpledb.ReplaceableAttribute{ // Required
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"), // Required
Replace: aws.Bool(true),
},
// More values...
},
Name: aws.String("String"), // Required
},
// More values...
},
}
resp, err := svc.BatchPutAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例2: ExampleSimpleDB_DeleteAttributes
func ExampleSimpleDB_DeleteAttributes() {
svc := simpledb.New(nil)
params := &simpledb.DeleteAttributesInput{
DomainName: aws.String("String"), // Required
ItemName: aws.String("String"), // Required
Attributes: []*simpledb.DeletableAttribute{
{ // Required
Name: aws.String("String"), // Required
Value: aws.String("String"),
},
// More values...
},
Expected: &simpledb.UpdateCondition{
Exists: aws.Bool(true),
Name: aws.String("String"),
Value: aws.String("String"),
},
}
resp, err := svc.DeleteAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例3: CreateAwsmDatabase
// CreateAwsmDatabase creates an awsm SimpleDB Domain
func CreateAwsmDatabase() error {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
params := &simpledb.CreateDomainInput{
DomainName: aws.String("awsm"),
}
_, err := svc.CreateDomain(params)
if err != nil {
return err
}
// Insert our default configs
Insert("securitygroups", DefaultSecurityGroupClasses())
Insert("vpcs", DefaultVpcClasses())
Insert("subnets", DefaultSubnetClasses())
Insert("instances", DefaultInstanceClasses())
Insert("alarms", DefaultAlarms())
Insert("images", DefaultImageClasses())
Insert("scalingpolicies", DefaultScalingPolicyClasses())
Insert("launchconfigurations", DefaultLaunchConfigurationClasses())
Insert("loadbalancers", DefaultLoadBalancerClasses())
Insert("volumes", DefaultVolumeClasses())
Insert("snapshots", DefaultSnapshotClasses())
Insert("autoscalegroups", DefaultAutoscaleGroupClasses())
Insert("keypairs", DefaultKeyPairClasses())
Insert("widgets", DefaultWidgets())
return nil
}
示例4: ExampleSimpleDB_Select
func ExampleSimpleDB_Select() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := simpledb.New(sess)
params := &simpledb.SelectInput{
SelectExpression: aws.String("String"), // Required
ConsistentRead: aws.Bool(true),
NextToken: aws.String("String"),
}
resp, err := svc.Select(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例5: TestResponseError
func TestResponseError(t *testing.T) {
for _, test := range responseErrorTests {
s := simpledb.New(nil)
s.Handlers.Send.Clear()
s.Handlers.Send.PushBack(func(r *request.Request) {
xml := createXMLResponse(test.requestID, test.errors)
body := ioutil.NopCloser(bytes.NewReader([]byte(xml)))
r.HTTPResponse = &http.Response{
ContentLength: int64(len(xml)),
StatusCode: test.scode,
Status: test.status,
Body: body,
}
})
_, err := s.CreateDomain(&simpledb.CreateDomainInput{
DomainName: aws.String("test-domain"),
})
assert.Error(t, err)
assert.Equal(t, test.code, err.(awserr.Error).Code())
assert.Equal(t, test.message, err.(awserr.Error).Message())
if len(test.errors) > 0 {
assert.Equal(t, test.requestID, err.(awserr.RequestFailure).RequestID())
assert.Equal(t, test.scode, err.(awserr.RequestFailure).StatusCode())
}
}
}
示例6: ExampleSimpleDB_GetAttributes
func ExampleSimpleDB_GetAttributes() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := simpledb.New(sess)
params := &simpledb.GetAttributesInput{
DomainName: aws.String("String"), // Required
ItemName: aws.String("String"), // Required
AttributeNames: []*string{
aws.String("String"), // Required
// More values...
},
ConsistentRead: aws.Bool(true),
}
resp, err := svc.GetAttributes(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例7: ExampleSimpleDB_ListDomains
func ExampleSimpleDB_ListDomains() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := simpledb.New(sess)
params := &simpledb.ListDomainsInput{
MaxNumberOfDomains: aws.Int64(1),
NextToken: aws.String("String"),
}
resp, err := svc.ListDomains(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例8: DeleteItemsByType
// DeleteItemsByType batch deletes classes from SimpleDB
func DeleteItemsByType(classType string) error {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
existingItems, err := GetItemsByType(classType)
if err != nil {
return err
}
params := &simpledb.BatchDeleteAttributesInput{
DomainName: aws.String("awsm"),
//Items: deleteList,
}
for _, item := range existingItems {
itemName := aws.StringValue(item.Name)
params.Items = append(params.Items, &simpledb.DeletableItem{
Name: item.Name,
})
terminal.Information("Deleting [" + classType + "/" + itemName + "] Configuration...")
}
_, err = svc.BatchDeleteAttributes(params)
if err != nil {
return err
}
terminal.Information("Done!")
return nil
}
示例9: GetItemByName
// GetItemByName gets a SimpleDB item by its type and name
func GetItemByName(classType, className string) (*simpledb.Item, error) {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
params := &simpledb.GetAttributesInput{
DomainName: aws.String("awsm"),
ItemName: aws.String(classType + "/" + className),
ConsistentRead: aws.Bool(true),
}
resp, err := svc.GetAttributes(params)
if err != nil {
return &simpledb.Item{}, err
}
if len(resp.Attributes) < 1 {
return &simpledb.Item{}, errors.New("Unable to find the [" + className + "] class in the database!")
}
item := &simpledb.Item{
Name: aws.String(classType + "/" + className),
Attributes: resp.Attributes,
}
return item, nil
}
示例10: DeleteSimpleDBDomains
// DeleteSimpleDBDomains deletes one or more SimpleDB Domains
func DeleteSimpleDBDomains(search, region string) (err error) {
domainList := new(SimpleDBDomains)
// Check if we were given a region or not
if region != "" {
err = GetRegionSimpleDBDomains(aws.String(region), domainList, search)
} else {
domainList, _ = GetSimpleDBDomains(search)
}
if err != nil {
terminal.ErrorLine("Error gathering SimpleDB domains list")
return
}
if len(*domainList) > 0 {
// Print the table
domainList.PrintTable()
} else {
terminal.ErrorLine("No SimpleDB Domains found, Aborting!")
return
}
// Confirm
if !terminal.PromptBool("Are you sure you want to delete these SimpleDB Domains?") {
terminal.ErrorLine("Aborting!")
return
}
// Delete 'Em
for _, domain := range *domainList {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String(domain.Region)}))
params := &simpledb.DeleteDomainInput{
DomainName: aws.String(domain.Name),
}
_, err = svc.DeleteDomain(params)
if err != nil {
terminal.ErrorLine("Error while deleting SimpleDB Domain [" + domain.Name + "] in [" + domain.Region + "], Aborting!")
return
}
terminal.Information("Deleted SimpleDB Domain [" + domain.Name + "] in [" + domain.Region + "]!")
}
terminal.Information("Done!")
return
}
示例11: CheckDB
// CheckDB checks for an awsm database
func CheckDB() bool {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
params := &simpledb.DomainMetadataInput{
DomainName: aws.String("awsm"), // Required
}
_, err := svc.DomainMetadata(params)
if err != nil {
return false
}
// TODO handle the response stats?
return true
}
示例12: ExampleSimpleDB_CreateDomain
func ExampleSimpleDB_CreateDomain() {
svc := simpledb.New(nil)
params := &simpledb.CreateDomainInput{
DomainName: aws.String("String"), // Required
}
resp, err := svc.CreateDomain(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例13: DeleteWidget
// DeleteWidget deletes a widget from SimpleDB
func DeleteWidget(widgetName string) error {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
itemName := "widgets/" + widgetName
params := &simpledb.DeleteAttributesInput{
DomainName: aws.String("awsm"),
ItemName: aws.String(itemName),
}
terminal.Information("Deleting [" + itemName + "] Configuration...")
_, err := svc.DeleteAttributes(params)
if err != nil {
return err
}
terminal.Information("Done!")
return nil
}
示例14: TestStatusCodeError
func TestStatusCodeError(t *testing.T) {
for _, test := range statusCodeErrorTests {
s := simpledb.New(nil)
s.Handlers.Send.Clear()
s.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte{}))
r.HTTPResponse = &http.Response{
ContentLength: 0,
StatusCode: test.scode,
Status: test.status,
Body: body,
}
})
_, err := s.CreateDomain(&simpledb.CreateDomainInput{
DomainName: aws.String("test-domain"),
})
assert.Error(t, err)
assert.Equal(t, test.code, err.(awserr.Error).Code())
assert.Equal(t, test.message, err.(awserr.Error).Message())
}
}
示例15: GetItemsByType
// GetItemsByType returns all SimpleDB items by class type
func GetItemsByType(classType string) ([]*simpledb.Item, error) {
svc := simpledb.New(session.New(&aws.Config{Region: aws.String("us-east-1")})) // TODO handle default region preference
params := &simpledb.SelectInput{
SelectExpression: aws.String(fmt.Sprintf("select * from awsm where classType = '%s'", classType)),
ConsistentRead: aws.Bool(true),
//NextToken: aws.String("String"),
}
resp, err := svc.Select(params)
if err != nil {
return []*simpledb.Item{}, err
}
if len(resp.Items) < 1 {
return []*simpledb.Item{}, errors.New("Unable to find the [" + classType + "] class in the database!")
}
return resp.Items, nil
}