當前位置: 首頁>>代碼示例>>Golang>>正文


Golang aws.StringSlice函數代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/aws.StringSlice函數的典型用法代碼示例。如果您正苦於以下問題:Golang StringSlice函數的具體用法?Golang StringSlice怎麽用?Golang StringSlice使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StringSlice函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: buildUpdateStackInput

func (s *CloudFormationStack) buildUpdateStackInput(stackName string, stackDetails StackDetails) *cloudformation.UpdateStackInput {
	updateStackInput := &cloudformation.UpdateStackInput{
		StackName:   aws.String(stackName),
		TemplateURL: aws.String(stackDetails.TemplateURL),
	}

	if len(stackDetails.Capabilities) > 0 {
		updateStackInput.Capabilities = aws.StringSlice(stackDetails.Capabilities)
	}

	if len(stackDetails.NotificationARNs) > 0 {
		updateStackInput.NotificationARNs = aws.StringSlice(stackDetails.NotificationARNs)
	}

	if len(stackDetails.Parameters) > 0 {
		updateStackInput.Parameters = BuilCloudFormationParameters(stackDetails.Parameters)
	}

	if len(stackDetails.ResourceTypes) > 0 {
		updateStackInput.ResourceTypes = aws.StringSlice(stackDetails.ResourceTypes)
	}

	if stackDetails.StackPolicyURL != "" {
		updateStackInput.StackPolicyURL = aws.String(stackDetails.StackPolicyURL)
	}

	return updateStackInput
}
開發者ID:cf-platform-eng,項目名稱:cloudformation-broker,代碼行數:28,代碼來源:cf_stack.go

示例2: tagSpotRequests

func (clst *amazonCluster) tagSpotRequests(awsIDs []awsID) error {
OuterLoop:
	for region, ids := range groupByRegion(awsIDs) {
		session := clst.getSession(region)
		spotIDs := getSpotIDs(ids)

		var err error
		for i := 0; i < 30; i++ {
			_, err = session.CreateTags(&ec2.CreateTagsInput{
				Tags: []*ec2.Tag{
					{
						Key:   aws.String(clst.namespace),
						Value: aws.String(""),
					},
				},
				Resources: aws.StringSlice(spotIDs),
			})
			if err == nil {
				continue OuterLoop
			}
			time.Sleep(5 * time.Second)
		}

		log.Warn("Failed to tag spot requests: ", err)
		session.CancelSpotInstanceRequests(
			&ec2.CancelSpotInstanceRequestsInput{
				SpotInstanceRequestIds: aws.StringSlice(spotIDs),
			})

		return err
	}

	return nil
}
開發者ID:yuenmeiwan,項目名稱:quilt,代碼行數:34,代碼來源:awsSpot.go

示例3: setDocumentPermissions

func setDocumentPermissions(d *schema.ResourceData, meta interface{}) error {
	ssmconn := meta.(*AWSClient).ssmconn

	log.Printf("[INFO] Setting permissions for document: %s", d.Id())
	permission := d.Get("permissions").(map[string]interface{})

	ids := aws.StringSlice([]string{permission["account_ids"].(string)})

	if strings.Contains(permission["account_ids"].(string), ",") {
		ids = aws.StringSlice(strings.Split(permission["account_ids"].(string), ","))
	}

	permInput := &ssm.ModifyDocumentPermissionInput{
		Name:            aws.String(d.Get("name").(string)),
		PermissionType:  aws.String(permission["type"].(string)),
		AccountIdsToAdd: ids,
	}

	_, err := ssmconn.ModifyDocumentPermission(permInput)

	if err != nil {
		return errwrap.Wrapf("[ERROR] Error setting permissions for SSM document: {{err}}", err)
	}

	return nil
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:26,代碼來源:resource_aws_ssm_document.go

示例4: convertToContainerDef

// convertToContainerDef transforms each service in the compose yml
// to an equivalent container definition
func convertToContainerDef(inputCfg *libcompose.ServiceConfig,
	volumes map[string]string, outputContDef *ecs.ContainerDefinition) error {
	// setting memory
	var mem int64
	if inputCfg.MemLimit != 0 {
		mem = inputCfg.MemLimit / kiB / kiB // convert bytes to MiB
	}
	if mem == 0 {
		mem = defaultMemLimit
	}

	// convert environment variables
	// TODO, read env file
	environment := []*ecs.KeyValuePair{}
	for _, env := range inputCfg.Environment.Slice() {
		parts := strings.SplitN(env, "=", 2)
		name := &parts[0]
		var value *string
		if len(parts) > 1 {
			value = &parts[1]
		}
		environment = append(environment, &ecs.KeyValuePair{
			Name:  name,
			Value: value,
		})
	}

	// convert port mappings
	portMappings, err := convertToPortMappings(*outputContDef.Name, inputCfg.Ports)
	if err != nil {
		return err
	}

	// convert volumes from
	volumesFrom := []*ecs.VolumeFrom{}
	for _, val := range inputCfg.VolumesFrom {
		volumeFrom := &ecs.VolumeFrom{
			SourceContainer: aws.String(val),
		}
		volumesFrom = append(volumesFrom, volumeFrom)
	}

	// convert mount points
	mountPoints, err := convertToMountPoints(inputCfg.Volumes, volumes)
	if err != nil {
		return err
	}
	// populating container definition, offloading the validation to aws-sdk
	outputContDef.Cpu = aws.Int64(inputCfg.CpuShares)
	outputContDef.Memory = aws.Int64(mem)
	outputContDef.EntryPoint = aws.StringSlice(inputCfg.Entrypoint.Slice())
	outputContDef.Command = aws.StringSlice(inputCfg.Command.Slice())
	outputContDef.Environment = environment
	outputContDef.Image = aws.String(inputCfg.Image)
	outputContDef.Links = aws.StringSlice(inputCfg.Links.Slice()) //TODO, read from external links
	outputContDef.MountPoints = mountPoints
	outputContDef.PortMappings = portMappings
	outputContDef.VolumesFrom = volumesFrom
	return nil
}
開發者ID:jloper3,項目名稱:amazon-ecs-cli,代碼行數:62,代碼來源:convert_task_definition.go

示例5: Stop

func (clst amazonCluster) Stop(machines []Machine) error {
	var awsIDs []awsID
	for _, m := range machines {
		awsIDs = append(awsIDs, awsID{
			region: m.Region,
			spotID: m.ID,
		})
	}
	for region, ids := range groupByRegion(awsIDs) {
		session := clst.getSession(region)
		spotIDs := getSpotIDs(ids)

		spots, err := session.DescribeSpotInstanceRequests(
			&ec2.DescribeSpotInstanceRequestsInput{
				SpotInstanceRequestIds: aws.StringSlice(spotIDs),
			})
		if err != nil {
			return err
		}

		instIds := []string{}
		for _, spot := range spots.SpotInstanceRequests {
			if spot.InstanceId != nil {
				instIds = append(instIds, *spot.InstanceId)
			}
		}

		if len(instIds) > 0 {
			_, err = session.TerminateInstances(&ec2.TerminateInstancesInput{
				InstanceIds: aws.StringSlice(instIds),
			})
			if err != nil {
				return err
			}
		}

		_, err = session.CancelSpotInstanceRequests(
			&ec2.CancelSpotInstanceRequestsInput{
				SpotInstanceRequestIds: aws.StringSlice(spotIDs),
			})
		if err != nil {
			return err
		}

		if err := clst.wait(ids, false); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:yuenmeiwan,項目名稱:quilt,代碼行數:51,代碼來源:awsSpot.go

示例6: dropGeneratedSecurityGroup

func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string {
	conn := meta.(*AWSClient).ec2conn

	groups := strings.Split(settingValue, ",")

	// Check to see if groups are ec2-classic or vpc security groups
	ec2Classic := true
	beanstalkSGRegexp := "sg-[0-9a-fA-F]{8}"
	for _, g := range groups {
		if ok, _ := regexp.MatchString(beanstalkSGRegexp, g); ok {
			ec2Classic = false
			break
		}
	}

	var resp *ec2.DescribeSecurityGroupsOutput
	var err error

	if ec2Classic {
		resp, err = conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
			GroupNames: aws.StringSlice(groups),
		})
	} else {
		resp, err = conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
			GroupIds: aws.StringSlice(groups),
		})
	}

	if err != nil {
		log.Printf("[DEBUG] Elastic Beanstalk error describing SecurityGroups: %v", err)
		return settingValue
	}

	log.Printf("[DEBUG] Elastic Beanstalk using ec2-classic security-groups: %t", ec2Classic)
	var legitGroups []string
	for _, group := range resp.SecurityGroups {
		log.Printf("[DEBUG] Elastic Beanstalk SecurityGroup: %v", *group.GroupName)
		if !strings.HasPrefix(*group.GroupName, "awseb") {
			if ec2Classic {
				legitGroups = append(legitGroups, *group.GroupName)
			} else {
				legitGroups = append(legitGroups, *group.GroupId)
			}
		}
	}

	sort.Strings(legitGroups)

	return strings.Join(legitGroups, ",")
}
開發者ID:Zordrak,項目名稱:terraform,代碼行數:50,代碼來源:resource_aws_elastic_beanstalk_environment.go

示例7: convertMapToSlice

// convertMapToSlice converts the map [String -> bool] to a AWS String Slice that is used by our APIs as input
func convertMapToSlice(mapItems map[string]bool) []*string {
	sliceItems := make([]string, 0, len(mapItems))
	for key := range mapItems {
		sliceItems = append(sliceItems, key)
	}
	return aws.StringSlice(sliceItems)
}
開發者ID:uttarasridhar,項目名稱:amazon-ecs-cli,代碼行數:8,代碼來源:entity.go

示例8: resourceAwsVPCEndpointRouteTableAssociationDelete

func resourceAwsVPCEndpointRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).ec2conn
	endpointId := d.Get("vpc_endpoint_id").(string)
	rtId := d.Get("route_table_id").(string)

	input := &ec2.ModifyVpcEndpointInput{
		VpcEndpointId:       aws.String(endpointId),
		RemoveRouteTableIds: aws.StringSlice([]string{rtId}),
	}

	_, err := conn.ModifyVpcEndpoint(input)
	if err != nil {
		ec2err, ok := err.(awserr.Error)
		if !ok {
			return fmt.Errorf("Error deleting VPC Endpoint/Route Table association: %s", err.Error())
		}

		switch ec2err.Code() {
		case "InvalidVpcEndpointId.NotFound":
			fallthrough
		case "InvalidRouteTableId.NotFound":
			fallthrough
		case "InvalidParameter":
			log.Printf("[DEBUG] VPC Endpoint/Route Table association is already gone")
		default:
			return fmt.Errorf("Error deleting VPC Endpoint/Route Table association: %s", err.Error())
		}
	}

	log.Printf("[DEBUG] VPC Endpoint/Route Table association %q deleted", d.Id())
	d.SetId("")

	return nil
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:34,代碼來源:resource_aws_vpc_endpoint_route_table_association.go

示例9: resourceAwsVPCEndpointRouteTableAssociationCreate

func resourceAwsVPCEndpointRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
	conn := meta.(*AWSClient).ec2conn
	endpointId := d.Get("vpc_endpoint_id").(string)
	rtId := d.Get("route_table_id").(string)

	_, err := findResourceVPCEndpoint(conn, endpointId)
	if err != nil {
		return err
	}

	log.Printf(
		"[INFO] Creating VPC Endpoint/Route Table association: %s => %s",
		endpointId, rtId)

	input := &ec2.ModifyVpcEndpointInput{
		VpcEndpointId:    aws.String(endpointId),
		AddRouteTableIds: aws.StringSlice([]string{rtId}),
	}

	_, err = conn.ModifyVpcEndpoint(input)
	if err != nil {
		return fmt.Errorf("Error creating VPC Endpoint/Route Table association: %s", err.Error())
	}
	id := vpcEndpointIdRouteTableIdHash(endpointId, rtId)
	log.Printf("[DEBUG] VPC Endpoint/Route Table association %q created.", id)

	d.SetId(id)

	return resourceAwsVPCEndpointRouteTableAssociationRead(d, meta)
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:30,代碼來源:resource_aws_vpc_endpoint_route_table_association.go

示例10: dropGeneratedSecurityGroup

func dropGeneratedSecurityGroup(settingValue string, meta interface{}) string {
	conn := meta.(*AWSClient).ec2conn

	groups := strings.Split(settingValue, ",")

	resp, err := conn.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
		GroupIds: aws.StringSlice(groups),
	})

	if err != nil {
		log.Printf("[DEBUG] Elastic Beanstalk error describing SecurityGroups: %v", err)
		return settingValue
	}

	var legitGroups []string
	for _, group := range resp.SecurityGroups {
		log.Printf("[DEBUG] Elastic Beanstalk SecurityGroup: %v", *group.GroupName)
		if !strings.HasPrefix(*group.GroupName, "awseb") {
			legitGroups = append(legitGroups, *group.GroupId)
		}
	}

	sort.Strings(legitGroups)

	return strings.Join(legitGroups, ",")
}
開發者ID:ewdurbin,項目名稱:terraform,代碼行數:26,代碼來源:resource_aws_elastic_beanstalk_environment.go

示例11: RunTaskWithOverrides

// RunTask issues a run task request for the input task definition
func (client *ecsClient) RunTaskWithOverrides(taskDefinition, startedBy string, count int, overrides map[string]string) (*ecs.RunTaskOutput, error) {

	commandOverrides := []*ecs.ContainerOverride{}
	for cont, command := range overrides {
		contOverride := &ecs.ContainerOverride{
			Name:    aws.String(cont),
			Command: aws.StringSlice([]string{command}),
		}
		commandOverrides = append(commandOverrides, contOverride)
	}
	ecsOverrides := &ecs.TaskOverride{
		ContainerOverrides: commandOverrides,
	}

	resp, err := client.client.RunTask(&ecs.RunTaskInput{
		Cluster:        aws.String(client.params.Cluster),
		TaskDefinition: aws.String(taskDefinition),
		StartedBy:      aws.String(startedBy),
		Count:          aws.Int64(int64(count)),
		Overrides:      ecsOverrides,
	})
	if err != nil {
		log.WithFields(log.Fields{
			"task definition": taskDefinition,
			"error":           err,
		}).Error("Error running tasks")
	}
	return resp, err
}
開發者ID:skion,項目名稱:amazon-ecs-cli,代碼行數:30,代碼來源:client.go

示例12: TestStringValueSlice

func TestStringValueSlice(t *testing.T) {
	for idx, in := range testCasesStringValueSlice {
		if in == nil {
			continue
		}
		out := aws.StringValueSlice(in)
		assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
		for i := range out {
			if in[i] == nil {
				assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
			} else {
				assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
			}
		}

		out2 := aws.StringSlice(out)
		assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
		for i := range out2 {
			if in[i] == nil {
				assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
			} else {
				assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
			}
		}
	}
}
開發者ID:Talos208,項目名稱:aws-sdk-go,代碼行數:26,代碼來源:convutil_test.go

示例13: GetEc2PrivateIpsFromInstanceIds

func GetEc2PrivateIpsFromInstanceIds(ec2_obj *ec2.EC2, instance_ids []string, debug bool) ([]string, error) {
	params := &ec2.DescribeInstancesInput{
		InstanceIds: aws.StringSlice(instance_ids),
	}
	resp, err := ec2_obj.DescribeInstances(params)

	if err != nil {
		return []string{}, fmt.Errorf("Cannot retrieve EC2 instance information: %s", FormatAwsError(err))
	}

	if len(resp.Reservations) <= 0 {
		return []string{}, fmt.Errorf("No EC2 instances found (Reservations.*) with specified Instance IDs filter: ", strings.Join(instance_ids, ", "))
	}
	if len(resp.Reservations[0].Instances) <= 0 {
		return []string{}, fmt.Errorf("No EC2 instances found (Reservations[0].* with specified Instance IDs filter: ", strings.Join(instance_ids, ", "))
	}

	var result []string
	for idx, _ := range resp.Reservations {
		for _, value := range resp.Reservations[idx].Instances {
			if *value.State.Name == "running" {
				result = append(result, *value.PrivateIpAddress)
			} else {
				if debug == true {
					fmt.Println(*value.InstanceId, "is not in a running state, excluded from results.")
				}
			}
		}
	}

	if len(result) == 0 {
		return []string{}, fmt.Errorf("No running EC2 instances found in result set, cannot proceed.")
	}
	return result, nil
}
開發者ID:CpuID,項目名稱:ecs-discoverer,代碼行數:35,代碼來源:shared.go

示例14: GetEc2InstanceIdsFromContainerInstances

func GetEc2InstanceIdsFromContainerInstances(ecs_obj *ecs.ECS, cluster string, container_instances []string, debug bool) ([]string, error) {
	params := &ecs.DescribeContainerInstancesInput{
		Cluster:            aws.String(cluster),
		ContainerInstances: aws.StringSlice(container_instances),
	}
	resp, err := ecs_obj.DescribeContainerInstances(params)

	if err != nil {
		return []string{}, fmt.Errorf("Cannot retrieve ECS container instance information: %s", FormatAwsError(err))
	}

	if len(resp.ContainerInstances) <= 0 {
		return []string{}, fmt.Errorf("No ECS container instances found with specified filter - cluster:", cluster, "- instances:", strings.Join(container_instances, ", "))
	}

	var result []string
	for _, value := range resp.ContainerInstances {
		if *value.Status == "ACTIVE" {
			result = append(result, *value.Ec2InstanceId)
		} else {
			if debug == true {
				fmt.Println(*value.Ec2InstanceId, "is not in an ACTIVE state, excluded from results.")
			}
		}
	}

	if len(result) == 0 {
		return []string{}, fmt.Errorf("No running ECS container instances found in result set, cannot proceed.")
	}
	return result, nil
}
開發者ID:CpuID,項目名稱:ecs-discoverer,代碼行數:31,代碼來源:shared.go

示例15: getQueueAttributes

func (s *SQSQueue) getQueueAttributes(queueURL string) (map[string]string, error) {
	getQueueAttributesInput := &sqs.GetQueueAttributesInput{
		QueueUrl:       aws.String(queueURL),
		AttributeNames: aws.StringSlice([]string{"All"}),
	}
	s.logger.Debug("get-queue-attributes", lager.Data{"input": getQueueAttributesInput})

	getQueueAttributesOutput, err := s.sqssvc.GetQueueAttributes(getQueueAttributesInput)
	if err != nil {
		s.logger.Error("aws-sqs-error", err)
		if awsErr, ok := err.(awserr.Error); ok {
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// AWS SQS returns a 400 if Queue is not found
				if reqErr.StatusCode() == 400 || reqErr.StatusCode() == 404 {
					return nil, ErrQueueDoesNotExist
				}
			}
			return nil, errors.New(awsErr.Code() + ": " + awsErr.Message())
		}
		return nil, err
	}
	s.logger.Debug("get-queue-attributes", lager.Data{"output": getQueueAttributesOutput})

	return aws.StringValueMap(getQueueAttributesOutput.Attributes), nil
}
開發者ID:cf-platform-eng,項目名稱:sqs-broker,代碼行數:25,代碼來源:sqs_queue.go


注:本文中的github.com/aws/aws-sdk-go/aws.StringSlice函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。