3

I dont understand what the error means but I think it is getting confused between the package in absolute path and in the vendor path. How do I make it not confused?

# 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

Here is the minimum reproducible code

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
}

EDIT: Solution

go mod vendor
go build -v
Souradeep Nanda
  • 3,116
  • 2
  • 30
  • 44
  • 3
    The error means that the two types, although equivalent, because they live in separate packages, are treated as different. To make the code work, you can either import `oss` from the `github.com/terraform-providers/terraform-provider-alicloud/vendor/....` path. Or have *your* app vendor both `connectivity` and `oss`. – mkopriva Sep 16 '19 at 15:43
  • @mkopriva that seems like it would be good enough for an answer if you want to post it and flesh it out with a reference to documentation about this. – ydaetskcoR Sep 16 '19 at 16:03
  • @mkopriva Vendoring both worked. `go mod vendor` `go build -v` Can you add this as an answer, I will accept it. – Souradeep Nanda Sep 18 '19 at 04:03

2 Answers2

1

The error means that the two types, although equivalent, because they live in separate packages, are treated as different. To make the code work, you can either import oss from the github.com/terraform-providers/terraform-provider-alicloud/vendor/... path. Or have your app vendor both connectivity and oss.

mkopriva
  • 35,176
  • 4
  • 57
  • 71
-1

The compiler cannot replace "github.com/aliyun/aliyun-oss-go-sdk/oss".Client with github.com/terraform-providers/terraform-provider-alicloud/vendor/github.com/aliyun/aliyun-oss-go-sdk/oss".Client, even they have the same name(but from different package).

cfmy
  • 11
  • 3