1

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

1
  • 6
    Read the message carefully: These are different types. One is from package .../furtif/vendor..., the other from .../security/vendor/.... Fix your vendoring. Commented Aug 16, 2017 at 7:25

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

It's not the import statements at issue. It's that there are two separately-vendored copies of the same library in the GOPATH - seems like they've imported a library that uses vendoring which is, as always, a Bad Thing™.
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.