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


Golang aws.StringValue函數代碼示例

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


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

示例1: handleSingleMessage

// handleSingleMessage processes a single refresh credentials message.
func (refreshHandler *refreshCredentialsHandler) handleSingleMessage(message *ecsacs.IAMRoleCredentialsMessage) error {
	// Validate fields in the message
	err := validateIAMRoleCredentialsMessage(message)
	if err != nil {
		seelog.Errorf("Error validating credentials message: %v", err)
		return err
	}
	taskArn := aws.StringValue(message.TaskArn)
	messageId := aws.StringValue(message.MessageId)
	task, ok := refreshHandler.taskEngine.GetTaskByArn(taskArn)
	if !ok {
		seelog.Errorf("Task not found in the engine for the arn in credentials message, arn: %s, messageId: %s", taskArn, messageId)
		return fmt.Errorf("Task not found in the engine for the arn in credentials message, arn: %s", taskArn)
	}
	taskCredentials := credentials.TaskIAMRoleCredentials{
		ARN:                taskArn,
		IAMRoleCredentials: credentials.IAMRoleCredentialsFromACS(message.RoleCredentials),
	}
	err = refreshHandler.credentialsManager.SetTaskCredentials(taskCredentials)
	if err != nil {
		seelog.Errorf("Error updating credentials, err: %v messageId: %s", err, messageId)
		return fmt.Errorf("Error updating credentials %v", err)
	}
	task.SetCredentialsId(aws.StringValue(message.RoleCredentials.CredentialsId))

	go func() {
		response := &ecsacs.IAMRoleCredentialsAckRequest{
			Expiration:    message.RoleCredentials.Expiration,
			MessageId:     message.MessageId,
			CredentialsId: message.RoleCredentials.CredentialsId,
		}
		refreshHandler.ackRequest <- response
	}()
	return nil
}
開發者ID:witsoej,項目名稱:amazon-ecs-agent,代碼行數:36,代碼來源:refresh_credentials_handler.go

示例2: Down

// Down stops any running containers(tasks) by calling Stop() and deletes an active ECS Service
// NoOp if the service is inactive
func (s *Service) Down() error {
	// describe the service
	ecsService, err := s.describeService()
	if err != nil {
		return err
	}

	ecsServiceName := aws.StringValue(ecsService.ServiceName)
	// if already deleted, NoOp
	if aws.StringValue(ecsService.Status) != ecsActiveResourceCode {
		log.WithFields(log.Fields{
			"serviceName": ecsServiceName,
		}).Info("ECS Service is already deleted")
		return nil
	}

	// stop any running tasks
	if aws.Int64Value(ecsService.DesiredCount) != 0 {
		if err = s.Stop(); err != nil {
			return err
		}
	}

	// deleteService
	if err = s.Context().ECSClient.DeleteService(ecsServiceName); err != nil {
		return err
	}
	return waitForServiceTasks(s, ecsServiceName)
}
開發者ID:jloper3,項目名稱:amazon-ecs-cli,代碼行數:31,代碼來源:service.go

示例3: Release

// Release releases all address for the given region/client
//
// TODO(rjeczalik): add logger
func (a *Addresses) Release(client *amazon.Client) {
	if len(a.m) == 0 {
		return
	}

	addresses := a.m[client]
	fmt.Printf("Releasing %d addresses for region %s\n", len(addresses), client.Region)
	for _, addr := range addresses {
		ip := aws.StringValue(addr.PublicIp)

		assocID := aws.StringValue(addr.AssociationId)
		if assocID != "" {
			// EIP is in-use, disassociate it first.
			err := client.DisassociateAddress(assocID)
			if err != nil {
				// Even when it fails, will try to release the EIP.
				fmt.Printf("[%s] disassociate %s EIP error: %s\n", client.Region, ip, err)
			}
		}

		allocID := aws.StringValue(addr.AllocationId)
		err := client.ReleaseAddress(allocID)
		if err != nil {
			fmt.Printf("[%s] release %s EIP error: %s\n", client.Region, ip, err)
		}
	}

	fmt.Printf("Releasing is done for region %s\n", client.Region)
}
開發者ID:koding,項目名稱:koding,代碼行數:32,代碼來源:addresses.go

示例4: discoverTags

func (a *AWSVolumes) discoverTags() error {
	instance, err := a.describeInstance()
	if err != nil {
		return err
	}

	tagMap := make(map[string]string)
	for _, tag := range instance.Tags {
		tagMap[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
	}

	clusterID := tagMap[TagNameKubernetesCluster]
	if clusterID == "" {
		return fmt.Errorf("Cluster tag %q not found on this instance (%q)", TagNameKubernetesCluster, a.instanceId)
	}

	a.clusterTag = clusterID

	a.internalIP = net.ParseIP(aws.StringValue(instance.PrivateIpAddress))
	if a.internalIP == nil {
		return fmt.Errorf("Internal IP not found on this instance (%q)", a.instanceId)
	}

	return nil
}
開發者ID:crohling,項目名稱:kops,代碼行數:25,代碼來源:aws_volume.go

示例5: CheckDataAndGetSize

func (s3 *s3driver) CheckDataAndGetSize(dpconn, itemlocation, fileName string) (exist bool, size int64, err error) {
	bucket := getAwsInfoFromDpconn(dpconn)

	destFullPathFileName := bucket + "/" + itemlocation + "/" + fileName
	log.Info(destFullPathFileName)

	AWS_REGION = Env("AWS_REGION", false)

	svc := s3aws.New(session.New(&aws.Config{Region: aws.String(AWS_REGION)}))
	result, err := svc.ListObjects(&s3aws.ListObjectsInput{Bucket: aws.String(bucket),
		Prefix: aws.String(itemlocation + "/" + fileName)})
	if err != nil {
		log.Error("Failed to list objects", err)
		return exist, size, err
	}

	exist = false
	for _, v := range result.Contents {
		log.Infof("Tag:%s, key:%s, size:%v\n", aws.StringValue(v.ETag), aws.StringValue(v.Key), aws.Int64Value(v.Size))
		if aws.StringValue(v.Key) == fileName {
			size = aws.Int64Value(v.Size)
			exist = true
		}
	}

	return
}
開發者ID:asiainfoLDP,項目名稱:datahub,代碼行數:27,代碼來源:s3driver.go

示例6: ListResources

func (c *DeleteCluster) ListResources() (map[string]*ResourceTracker, error) {
	cloud := c.Cloud.(*awsup.AWSCloud)

	resources := make(map[string]*ResourceTracker)

	listFunctions := []listFn{
		ListSubnets, ListRouteTables, ListSecurityGroups,
		ListInstances, ListDhcpOptions, ListInternetGateways, ListVPCs, ListVolumes,
		// ELBs
		ListELBs,
		// ASG
		ListAutoScalingGroups,
		ListAutoScalingLaunchConfigurations,
	}
	for _, fn := range listFunctions {
		trackers, err := fn(cloud, c.ClusterName)
		if err != nil {
			return nil, err
		}
		for _, t := range trackers {
			resources[t.Type+":"+t.ID] = t
		}
	}

	{
		// Gateways weren't tagged in kube-up
		// If we are deleting the VPC, we should delete the attached gateway
		// (no real reason not to; easy to recreate; no real state etc)

		gateways, err := DescribeInternetGatewaysIgnoreTags(cloud)
		if err != nil {
			return nil, err
		}

		for _, igw := range gateways {
			for _, attachment := range igw.Attachments {
				vpcID := aws.StringValue(attachment.VpcId)
				igwID := aws.StringValue(igw.InternetGatewayId)
				if vpcID == "" || igwID == "" {
					continue
				}
				if resources["vpc:"+vpcID] != nil && resources["internet-gateway:"+igwID] == nil {
					resources["internet-gateway:"+igwID] = &ResourceTracker{
						Name:    FindName(igw.Tags),
						ID:      igwID,
						Type:    "internet-gateway",
						deleter: DeleteInternetGateway,
					}
				}
			}
		}
	}

	for k, t := range resources {
		if t.done {
			delete(resources, k)
		}
	}
	return resources, nil
}
開發者ID:crohling,項目名稱:kops,代碼行數:60,代碼來源:delete_cluster.go

示例7: ListVPCs

func ListVPCs(cloud fi.Cloud, clusterName string) ([]*ResourceTracker, error) {
	c := cloud.(*awsup.AWSCloud)

	glog.V(2).Infof("Listing EC2 VPC")
	request := &ec2.DescribeVpcsInput{
		Filters: buildEC2Filters(cloud),
	}
	response, err := c.EC2.DescribeVpcs(request)
	if err != nil {
		return nil, fmt.Errorf("error listing VPCs: %v", err)
	}

	var trackers []*ResourceTracker

	for _, v := range response.Vpcs {
		tracker := &ResourceTracker{
			Name:    FindName(v.Tags),
			ID:      aws.StringValue(v.VpcId),
			Type:    "vpc",
			deleter: DeleteVPC,
		}

		var blocks []string
		blocks = append(blocks, "dhcp-options:"+aws.StringValue(v.DhcpOptionsId))

		tracker.blocks = blocks

		trackers = append(trackers, tracker)
	}

	return trackers, nil
}
開發者ID:crohling,項目名稱:kops,代碼行數:32,代碼來源:delete_cluster.go

示例8: constructTaskDefinitionCacheHash

// constructTaskDefinitionCacheHash computes md5sum of the region, awsAccountId and the requested task definition data
// BUG(juanrhenals) The requested Task Definition data (taskDefinitionRequest) is not created in a deterministic fashion because there are maps within
// the request ecs.RegisterTaskDefinitionInput structure, and map iteration in Go is not deterministic. We need to fix this.
func (client *ecsClient) constructTaskDefinitionCacheHash(taskDefinition *ecs.TaskDefinition, request *ecs.RegisterTaskDefinitionInput) string {
	// Get the region from the ecsClient configuration
	region := aws.StringValue(client.params.Config.Region)
	awsUserAccountId := utils.GetAwsAccountIdFromArn(aws.StringValue(taskDefinition.TaskDefinitionArn))
	tdHashInput := fmt.Sprintf("%s-%s-%s", region, awsUserAccountId, request.GoString())
	return fmt.Sprintf("%x", md5.Sum([]byte(tdHashInput)))
}
開發者ID:skion,項目名稱:amazon-ecs-cli,代碼行數:10,代碼來源:client.go

示例9: clientConfigWithErr

func (s *Session) clientConfigWithErr(serviceName string, cfgs ...*aws.Config) (client.Config, error) {
	s = s.Copy(cfgs...)

	var resolved endpoints.ResolvedEndpoint
	var err error

	region := aws.StringValue(s.Config.Region)

	if endpoint := aws.StringValue(s.Config.Endpoint); len(endpoint) != 0 {
		resolved.URL = endpoints.AddScheme(endpoint, aws.BoolValue(s.Config.DisableSSL))
		resolved.SigningRegion = region
	} else {
		resolved, err = s.Config.EndpointResolver.EndpointFor(
			serviceName, region,
			func(opt *endpoints.Options) {
				opt.DisableSSL = aws.BoolValue(s.Config.DisableSSL)
				opt.UseDualStack = aws.BoolValue(s.Config.UseDualStack)
			},
		)
	}

	return client.Config{
		Config:        s.Config,
		Handlers:      s.Handlers,
		Endpoint:      resolved.URL,
		SigningRegion: resolved.SigningRegion,
		SigningName:   resolved.SigningName,
	}, err
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:29,代碼來源:session.go

示例10: PutObject

func (fs3 *fakeS3) PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error) {
	k := aws.StringValue(input.Key)
	bucket := aws.StringValue(input.Bucket)

	if strings.HasSuffix(k, "meta.json") {
		data, err := ioutil.ReadAll(input.Body)
		if err != nil {
			return nil, fmt.Errorf("Failed to read body for key %s: %v", k, err)
		}
		fs3.m.Lock()
		fs3.metadata = data
		fs3.m.Unlock()
	} else {
		// gunzip the data and store that
		gzr, err := gzip.NewReader(input.Body)
		if err != nil {
			return nil, fmt.Errorf("Failed to gunzip key %s: %v", k, err)
		}

		data, err := ioutil.ReadAll(gzr)
		if err != nil {
			return nil, fmt.Errorf("Failed to read body for key %s: %v", k, err)
		}

		fs3.m.Lock()
		fs3.parts[k] = putdata{
			data:   data,
			bucket: bucket,
			enc:    aws.StringValue(input.ContentEncoding),
			ctype:  aws.StringValue(input.ContentType),
		}
		fs3.m.Unlock()
	}
	return nil, nil
}
開發者ID:gwatts,項目名稱:dyndump,代碼行數:35,代碼來源:s3writer_test.go

示例11: CreateSnapshot

// CreateSnapshot creates a new snapshot from the given volumeId and
// description. It waits until it's ready.
func (a *Amazon) CreateSnapshot(volumeId, desc string) (*ec2.Snapshot, error) {
	snapshot, err := a.Client.CreateSnapshot(volumeId, desc)
	if err != nil {
		return nil, err
	}

	checkSnapshot := func(int) (machinestate.State, error) {
		s, err := a.Client.SnapshotByID(aws.StringValue(snapshot.SnapshotId))
		if IsNotFound(err) {
			// shouldn't happen but let's check it anyway
			return machinestate.Pending, nil
		}
		if err != nil {
			return 0, err
		}
		if aws.StringValue(s.State) != ec2.SnapshotStateCompleted {
			return machinestate.Pending, nil
		}
		snapshot = s
		return machinestate.Stopped, nil
	}

	ws := waitstate.WaitState{
		StateFunc:    checkSnapshot,
		DesiredState: machinestate.Stopped,
	}
	if err := ws.Wait(); err != nil {
		return nil, err
	}

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

示例12: handleSingleMessage

// handleSingleMessage processes a single payload message. It adds tasks in the message to the task engine
// An error is returned if the message was not handled correctly. The error is being used only for testing
// today. In the future, it could be used for doing more interesting things.
func (payloadHandler *payloadRequestHandler) handleSingleMessage(payload *ecsacs.PayloadMessage) error {
	if aws.StringValue(payload.MessageId) == "" {
		seelog.Criticalf("Recieved a payload with no message id, payload: %v", payload)
		return fmt.Errorf("Received a payload with no message id")
	}
	seelog.Debugf("Received payload message, message id: %s", aws.StringValue(payload.MessageId))
	credentialsAcks, allTasksHandled := payloadHandler.addPayloadTasks(payload)
	// save the state of tasks we know about after passing them to the task engine
	err := payloadHandler.saver.Save()
	if err != nil {
		seelog.Errorf("Error saving state for payload message! err: %v, messageId: %s", err, *payload.MessageId)
		// Don't ack; maybe we can save it in the future.
		return fmt.Errorf("Error saving state for payload message, with messageId: %s", *payload.MessageId)
	}
	if !allTasksHandled {
		return fmt.Errorf("All tasks not handled")
	}

	go func() {
		// Throw the ack in async; it doesn't really matter all that much and this is blocking handling more tasks.
		for _, credentialsAck := range credentialsAcks {
			payloadHandler.refreshHandler.ackMessage(credentialsAck)
		}
		payloadHandler.ackRequest <- *payload.MessageId
	}()

	return nil
}
開發者ID:witsoej,項目名稱:amazon-ecs-agent,代碼行數:31,代碼來源:payload_handler.go

示例13: start

func (ld *loader) start(infoWriter io.Writer) (done chan error, err error) {
	var hashKey string
	for _, s := range ld.tableInfo.KeySchema {
		if aws.StringValue(s.KeyType) == "HASH" {
			hashKey = aws.StringValue(s.AttributeName)
		}
	}
	if hashKey == "" {
		fail("Failed to find hash key for table")
	}

	fmt.Fprintf(infoWriter, "Beginning restore: table=%q source=%q writeCapacity=%d parallel=%d totalSize=%s allow-overwrite=%t\n",
		*ld.tableName, ld.source, *ld.writeCapacity, *ld.parallel, fmtBytes(ld.md.UncompressedBytes), *ld.allowOverwrite)

	dynLoader := &dyndump.Loader{
		Dyn:            ld.dyn,
		TableName:      *ld.tableName,
		MaxParallel:    *ld.parallel,
		MaxItems:       int64(*ld.maxItems),
		WriteCapacity:  float64(*ld.writeCapacity),
		Source:         dyndump.NewSimpleDecoder(ld.r),
		HashKey:        hashKey,
		AllowOverwrite: *ld.allowOverwrite,
	}

	ld.loader = dynLoader
	done = make(chan error, 1)
	ld.startTime = time.Now()

	go func() {
		done <- dynLoader.Run()
	}()

	return done, nil
}
開發者ID:gwatts,項目名稱:dyndump,代碼行數:35,代碼來源:cmd_load.go

示例14: taskDefinitionToProcess

// taskDefinitionToProcess takes an ECS Task Definition and converts it to a
// Process.
func taskDefinitionToProcess(td *ecs.TaskDefinition) (*scheduler.Process, error) {
	// If this task definition has no container definitions, then something
	// funky is up.
	if len(td.ContainerDefinitions) == 0 {
		return nil, errors.New("task definition had no container definitions")
	}

	container := td.ContainerDefinitions[0]

	var command []string
	for _, s := range container.Command {
		command = append(command, *s)
	}

	env := make(map[string]string)
	for _, kvp := range container.Environment {
		if kvp != nil {
			env[aws.StringValue(kvp.Name)] = aws.StringValue(kvp.Value)
		}
	}

	return &scheduler.Process{
		Type:        aws.StringValue(container.Name),
		Command:     command,
		Env:         env,
		CPUShares:   uint(*container.Cpu),
		MemoryLimit: uint(*container.Memory) * MB,
		Nproc:       uint(softLimit(container.Ulimits, "nproc")),
	}, nil
}
開發者ID:mhahn,項目名稱:empire,代碼行數:32,代碼來源:ecs.go

示例15: ListSecurityGroups

func ListSecurityGroups(cloud fi.Cloud, clusterName string) ([]*ResourceTracker, error) {
	c := cloud.(*awsup.AWSCloud)

	glog.V(2).Infof("Listing EC2 SecurityGroups")
	request := &ec2.DescribeSecurityGroupsInput{
		Filters: buildEC2Filters(cloud),
	}
	response, err := c.EC2.DescribeSecurityGroups(request)
	if err != nil {
		return nil, fmt.Errorf("error listing SecurityGroups: %v", err)
	}

	var trackers []*ResourceTracker

	for _, sg := range response.SecurityGroups {
		tracker := &ResourceTracker{
			Name:    FindName(sg.Tags),
			ID:      aws.StringValue(sg.GroupId),
			Type:    "security-group",
			deleter: DeleteSecurityGroup,
		}

		var blocks []string
		blocks = append(blocks, "vpc:"+aws.StringValue(sg.VpcId))

		tracker.blocks = blocks

		trackers = append(trackers, tracker)
	}

	return trackers, nil
}
開發者ID:crohling,項目名稱:kops,代碼行數:32,代碼來源:delete_cluster.go


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