简体   繁体   English

golang中的类型不一致,无法使用 <Type> 如 <Type>

[英]Inconsistent type in golang, cannot use <Type> as <Type>

I am writing an application in Go that uses a Logger object type. 我正在Go中编写一个使用Logger对象类型的应用程序。
In it I use another application that uses the same logger object type: 在其中,我使用了另一个使用相同记录器对象类型的应用程序:
App1: 应用1:

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): App2(安全性。来自安全性库的新增功能):

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) 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 不能将* logger(类型为“ gitlab.sio.com/go/furtif/vendor/gitlab.sio.com/go/zlog”.Logger)用作“ gitlab.sio.com/go/security/vendor/gitlab.sio” .com / go / zlog”。安全性参数记录器。新

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. 如果您尝试仅将应用程序2用作库,则在应用程序2中删除供应商文件夹将解决此问题。

You need to fix your import statements to properly point the import types from where they should belong to. 您需要修复导入语句,以正确指出导入类型应从其所属的位置开始。 Read the error message. 阅读错误消息。

我发生此错误是因为我在同一包中多次声明了一个类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM