'Error while using gorilla/mux, "vendor/" befor the github path in import

It appears the error is regarding the vendor, i thought I didn't used it for this project but appears like a github package is being imported with a vendor/ prefix

here's the error print:

command-line-arguments

.\main.go:14:33: cannot use r (variable of type *"vendor/github.com/gorilla/mux".Router) as type *"github.com/gorilla/mux".Router in argument to routes.RegisterBookStoreRoutes

here the code in main.go


import (
    "log"
    "net/http"

    "github.com/AleAgu200/go-bookstore/pkg/routes"
    "github.com/gorilla/mux"
    _ "github.com/jinzhu/gorm/dialects/mysql"
)

func main(){
    r := mux.NewRouter() /* creamos un nuevo router */
    routes.RegisterBookStoreRoutes(r) /* registramos nuestras rutas */
    log.Fatal(http.ListenAndServe(":8080", r)) /* le decimos que escuche en el puerto 8080 */
}

and the code in the module for routes(file is called bookstore-routes.go)

package routes

/* aqui importamos los archivos o paquetes que necesitamos */
import (
    "github.com/AleAgu200/go-bookstore/pkg/controllers"
    "github.com/gorilla/mux"
)

/* aqui definimos nuestras rutas como una funcion de crear una libreria */
var RegisterBookStoreRoutes = func(router *mux.Router) {
    router.HandleFunc("/books", controllers.GetBooks).Methods("GET") /* ruta para tener todos los libros*/
    router.HandleFunc("/books/{id}", controllers.GetBook).Methods("GET") /* ruta para tener 1 libro por ID */
    router.HandleFunc("/books", controllers.CreateBook).Methods("POST") /* ruta para crear un libro */
    router.HandleFunc("/books/{id}", controllers.UpdateBook).Methods("PUT") /* ruta para actualizar un libro */
    router.HandleFunc("/books/{id}", controllers.DeleteBook).Methods("DELETE") /* ruta para eliminar un libro */
}
go


Solution 1:[1]

Try deleting the vendor folder and re-running go mod tidy in the root directory of your project (the one which contains your go.mod).

If you still need vendoring you have to re-run go mod vendor every time you want to update/change your dependencies.

Please have a look at the spec about vendoring for further information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cookie04