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

如何正确导入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 如何构建全国统一的物流管理平台?
  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥20 和学习数据的传参方式,选择正确的传参方式有关
  • ¥15 这是网络安全里面的poem code
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路