亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否可以將輸出更改為實際的字符串?

是否可以將輸出更改為實際的字符串?

Go
蕪湖不蕪 2023-07-10 14:22:33
我創建了這個函數來輸出跨區域的 aws 賬戶的所有賬戶 ID,但我得到的輸出非常難以理解嘗試像 c++ 中那樣取消引用package mainimport (    "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)}
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

*string當你真正只需要s 時,你卻在服用s string。這是一個簡單的更改,可以取消引用從 AWS SDK 返回的指針(它對所有內容都使用指針以實現可空性):


var accountList []string


for _, accountId := range result.Accounts {

    accountList = append(accountList, *accountId.Id)

}

fmt.Println(accountList)


查看完整回答
反對 回復 2023-07-10
  • 1 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號