如何让 golang 不混淆供应商导入和绝对导入?

How to make golang not confuse vendor import with absolute import?

我不明白这个错误是什么意思,但我认为绝对路径中的包和供应商路径中的包之间存在混淆。我怎样才能让它不混淆?

# 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

编译器无法将 "github.com/aliyun/aliyun-oss-go-sdk/oss".Client 替换为 github.com/terraform-providers/terraform-provider-alicloud/vendor/github.com/aliyun/aliyun-oss-go-sdk/oss" .Client,即使它们具有相同的名称(但来自不同的包)。

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