如何使golang不会使供应商的进口与绝对进口混淆?

时间:2019-09-16 12:53:12

标签: go terraform alibaba-cloud

我不明白该错误的含义,但我认为绝对路径和供应商路径中的程序包之间会混淆。如何使它不混乱?

# github.com/GoogleCloudPlatform/terraformer/providers/alicloud
providers/alicloud/dum.go:10:35: cannot use func literal (type func(*"github.com/aliyun/aliyun-oss-go-sdk/oss".Client) (interface {}, error)) as type func(*"github.com/terraform-providers/terraform-provider-alicloud/vendor/github.com/aliyun/aliyun-oss-go-sdk/oss".Client) (interface {}, error) in argument to client.WithOssClient

这是最小的可复制代码

package dum

import (
    oss "github.com/aliyun/aliyun-oss-go-sdk/oss"
    "github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity"
)

func dum() error {
    client := connectivity.AliyunClient{}
    raw, err := client.WithOssClient(func(ossClient *oss.Client) (interface{}, error) {
        return ossClient.ListBuckets()
    })
    if err != nil {
        return err
    }
    println(raw)

    return nil
}

编辑:解决方案

go mod vendor
go build -v

2 个答案:

答案 0 :(得分:1)

该错误意味着这两种类型虽然等效,但由于它们位于单独的程序包中,因此被视为不同。要使代码正常工作,您可以从oss路径导入github.com/terraform-providers/terraform-provider-alicloud/vendor/...。或者让您的应用程序供应商同时使用connectivityoss

答案 1 :(得分:-1)

编译器无法用 github.com/terraform-providers/terraform-provider-alicloud替换“ github.com/aliyun/aliyun-oss-go-sdk/oss”。客户端 /vendor/github.com/aliyun/aliyun-oss-go-sdk/oss“。客户端,即使它们具有相同的名称(但来自不同的软件包)。