2016-11-21 108 views
-1

我在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 

我不得不改变越来越导入的方法,但我怎么准确去做?

谢谢!

回答

0

这里的问题是,你的github.com/aws/aws-sdk-go/aws/session包是出售,它从文件夹stash/cloud/sphinx/vendor/github.com/aws/aws-sdk-go/aws加载。

但是,您想要通过它的功能:iam.New()未销售,它不是来自同一供应商文件夹(stash/cloud/sphinx/vendor/xxx),而是直接来自github.com/aws/aws-sdk-go/service/iam

要么将​​这两个软件包放在同一个供应商文件夹下,要么没有。您的某个依赖项工具可能会这样做(例如glide),在这种情况下,您应该指示您的工具以兼职方式处理这两者。