Amazon web services 是否可以将输出更改为实际的字符串?
我创建了这个函数来输出我的aws帐户跨区域的所有帐户ID,但是我得到的输出是非常难以理解的 尝试像在c中那样取消引用++Amazon web services 是否可以将输出更改为实际的字符串?,amazon-web-services,go,Amazon Web Services,Go,我创建了这个函数来输出我的aws帐户跨区域的所有帐户ID,但是我得到的输出是非常难以理解的 尝试像在c中那样取消引用++ package main import ( "fmt" //"github.com/aws/aws-lambda-go/lambda" // "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" //"github.com/aws/aws-sdk-g
package main
import (
"fmt"
//"github.com/aws/aws-lambda-go/lambda"
// "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
//"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/organizations"
)
func main() {
listAccounts()
}
func listAccounts() {
sess := session.Must(session.NewSession())
svc := organizations.New(sess)
input := &organizations.ListAccountsInput{}
result, err := svc.ListAccounts(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case organizations.ErrCodeAccessDeniedException:
fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error())
case organizations.ErrCodeAWSOrganizationsNotInUseException:
fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error())
case organizations.ErrCodeInvalidInputException:
fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error())
case organizations.ErrCodeServiceException:
fmt.Println(organizations.ErrCodeServiceException, aerr.Error())
case organizations.ErrCodeTooManyRequestsException:
fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
// fmt.Println(result.Accounts)
var accountList []*string
for _, accountId := range result.Accounts {
accountList = append(accountList, accountId.Id)
}
fmt.Println(accountList)
}
快跑id
[0xc0002387e0 0xc000238840 0xc0002388a0 0xc000238900 0xc000238960 0xc0002389c0 0xc000238a20 0xc000238a80 0xc000238ae0 0xc000238b40 0xc000238ba0 0xc000238c00 0xc000238cc0 0xc000238d20 0xc000238d80 0xc000238de0 0xc000238e40 0xc000238ea0 0xc000238f00]当您真正只需要
字符串时,您正在使用*string
s。这是一个简单的更改,可以取消从AWS SDK返回的指针的引用(它使用指针实现所有可空性):
你说你在尝试像在c++
中那样去引用,但你没有去引用任何东西。您是否需要使用[]字符串
或[]*字符串
?[]*字符串
让它知道如何分配var。我不明白这意味着什么fmt
显然不会以想要的方式打印[]*字符串,因此如果要打印它,需要在指针上迭代。最终目标是打印,还是将其整理成其他内容?将其用于lambda调用这意味着什么?是否需要将其格式化为字符串?是否需要将其格式化为json?如果是这种情况,为什么会有一个[]*字符串
?
var accountList []string
for _, accountId := range result.Accounts {
accountList = append(accountList, *accountId.Id)
}
fmt.Println(accountList)