Lucian
Lucian

Reputation: 894

Inconsistent type in golang, cannot use <Type> as <Type>

I am writing an application in Go that uses a Logger object type.
In it I use another application that uses the same logger object type:
App1:

import "gitlab.sio.com/go/zlog"

var logger = zlog.New(append(opts,
    zlog.App(c.Name, typ, version),
    zlog.Env(c.Environment),
)...)
....
router.GET("/get", GetHandler(logger))
....
func GetHandler(logger *zlog.Logger){
    ....
    mdl, _ := security.New(*logger)
    ....
}

App2(security.New from security lib):

package security

import "gitlab.sio.com/go/zlog"

Middleware struct {
    log             zlog.Logger
}

func New(log zlog.Logger){
...
mdw := Middleware{}
mdw.log = log
}

The error what I'm getting at line

mdl, _ := security.New(*logger)

is:

cannot use *logger (type "gitlab.sio.com/go/furtif/vendor/gitlab.sio.com/go/zlog".Logger) as type "gitlab.sio.com/go/security/vendor/gitlab.sio.com/go/zlog".Logger in argument to security.New

Upvotes: 1

Views: 9218

Answers (3)

ozzieisaacs
ozzieisaacs

Reputation: 843

This error happened to me because I had a type declared more than once across the same package.

Upvotes: -1

Gokul Raj Kumar
Gokul Raj Kumar

Reputation: 353

The issue is due to the same library imported in two different vendor folders. If you are trying to use the application 2 only as a library, removing the vendor folder in the application 2 will solve this issue.

Upvotes: 3

dlsniper
dlsniper

Reputation: 7477

You need to fix your import statements to properly point the import types from where they should belong to. Read the error message.

Upvotes: 1

Related Questions