Solve the problem of the same type caused by vendor in golang, but prompting different types

藏色散人
Release: 2021-01-07 16:33:12
forward
2395 people have browsed it

The following column golang tutorial will introduce to you the method to solve the same type of problem caused by the vendor in golang, but the prompts are of different types. I hope it will be helpful to friends who need it. Helps!

Solve the problem of the same type caused by vendor in golang, but prompting different types

Question:

In the project, I used my own secondary development framework based on the open source project gin. When registering the route An error message was prompted, as follows:

cannot use func literal (type func(*"github.com/dazhenghu/cms/vendor/github.com/gin-gonic/gin".Context)) as type "github.com/gin-gonic/gin".HandlerFunc in argument to indexInstace.Controller.Get
Copy after login

Analysis:

It can be seen from the prompt that although they are all of func(*Context) type (Note: The type of HandlerFunc is func(*Context), you can check it in the gin source code by yourself), but the packages of the two are different. Obviously, the former is the package under the vendor in my project. It prompts that the path of this package is inconsistent. It should be Different packages loaded by the project lead to

Solution:

By executing the add dependency command: govendor add github.com/dazhenghu/ginApp/controller, the framework developed by yourself will also First add it to the vendor for management, and then execute it again, this error will not be reported

For more related technical articles, please visit the go language tutorial column!

The above is the detailed content of Solve the problem of the same type caused by vendor in golang, but prompting different types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!