dtoq41429 2018-05-02 09:06
浏览 181
已采纳

如何正确导入aws-sdk-go服务?

I am fairly new to the Go programming language and completely new to the Go SDK from AWS. I am trying to use a service but I have a strange problem where the types defined by the imported service are found, but the functions of the service are undefined.

This question is not about using the particular service, but just how to correctly import it. My code:

package auth

import (
    "log"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)

func SignUpTest() {

    input := cognitoidentityprovider.SignUpInput{
        Username: aws.String("example@mail.com"),
        Password: aws.String("test1234"),
    }

    _, err := cognitoidentityprovider.SignUp(&input)

    if err != nil {
        log.Fatal(err)
    }
}

I get the following error when running go build:

auth/signup.go:18:12: undefined: cognitoidentityprovider.SignUp

The autocomplete in my IDE also states that it can find the cognitoidentityprovider.SingUpInput struct, but it is unable to find the cognitoidentityprovider.SignUp function.

I use Go 1.10.1 on WSL Ubuntu. I use DEP 0.4.1 for package management. I verified that the AWS SDK is available in the vendor folder and that the cognitoidentityprovider package is available (the SignUp) function is also there.

What am I missing here?

  • 写回答

1条回答 默认 最新

  • dsa4d4789789 2018-05-02 09:28
    关注

    The error says it all. cognitoidentityprovider.SignUp isn't defined, because there is no symbol SignUp exported by the cognitoidentityprovider package.

    I'm not really sure what you want to do instead, since I'm not familiar with that SDK, but you're trying to call a function that doesn't exist. I suggest re-examining the documentation or example you're following. You've probably made a simple mistake.

    You seem to be confused by the CognitoIdentityProvider.SignUp instance method. But as that's an instance method, and not an exported function, it requires an instance of a CognitoIdentityProvider first:

    cip := cognitoidentityprovider.New( ... )
    _, err := cip.SignUp(input)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型