gpt4 book ai didi

go - 如何更改导入文件?

转载 作者:数据小太阳 更新时间:2023-10-29 03:37:27 27 4
gpt4 key购买 nike

我在golang中有以下功能:

import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/aws/session"
"fmt"
)
func NewIAM() *SphinxIAM {
// awsConfig := aws.NewConfig()
sess, err := session.NewSession()
if err != nil {
fmt.Println("Failed to create session,", err)
return nil
}
session := &SphinxIAM{iam: iam.New(sess)}
return session
}

现在,当我运行它时出现以下错误:

cannot use sess (type *session.Session) as type "github.com/aws/aws-sdk-go/aws/client".ConfigProvider in argument to iam.New:
*session.Session does not implement "github.com/aws/aws-sdk-go/aws/client".ConfigProvider (wrong type for ClientConfig method)
have ClientConfig(string, ...*"stash/cloud/sphinx/vendor/github.com/aws/aws-sdk-go/aws".Config) "stash/cloud/sphinx/vendor/github.com/aws/aws-sdk-go/aws/client".Config
want ClientConfig(string, ...*"github.com/aws/aws-sdk-go/aws".Config) "github.com/aws/aws-sdk-go/aws/client".Config

我必须更改导入的方法,但我该怎么做呢?

谢谢!

最佳答案

这里的问题是您的 github.com/aws/aws-sdk-go/aws/session 包是 vendor ,它是从文件夹 stash/cloud/sphinx/vendor/github.com/aws/aws-sdk-go/aws

但是您要传递给它的函数:iam.New() 不是 vendored,它不是来自同一个 vendor 文件夹(stash/cloud/sphinx/vendor/xxx ) 但它直接来自 github.com/aws/aws-sdk-go/service/iam

要么将两个包放在同一个 vendor 文件夹下,要么不放。您的某个依赖项工具可能会执行此操作(例如 glide),在这种情况下,您应该指示您的工具将两者都处理为 vendored。

关于go - 如何更改导入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40714880/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com