2

I saw the similar question here. But I couldn't solve my case.

I am having project initialised with dep and added the first dependency "Echo". Now folder structure looks like this

|--server
|    |--server.go
|--vendor
|--main.go

The server.go has the following code

package server

import (
    "net/http"

    "github.com/labstack/echo"
)

// TestController : Test controller
func TestController(c echo.Context) error {
    return c.String(http.StatusOK, "Hello, World!")
}

and the main.go has

package main

import (
    "github.com/labstack/echo"
    "github.com/sfkshan/pos/server"
)

func main() {
    e := echo.New()
    e.GET("/", server.TestController)
    e.Logger.Fatal(e.Start(":1323"))
}

Now vscode shows the warning

cannot use server.TestController (type func("github.com/sfkshan/pos/vendor/github.com/labstack/echo".Context) error) as type "github.com/labstack/echo".HandlerFunc in argument to e.GET

I am not sure why is this happening? If I delete the vendor folder folder the error vanishes. But again after running dep ensure (in this case vendor folder gets created which is expected) the error appears again.

shanmugharaj
  • 3,814
  • 7
  • 42
  • 70
  • Did you already try to delete the folder in your GOPATH? It looks like Go gets mixed up on which package to use – Jonathan R Mar 10 '18 at 23:00
  • @JonathanR I am not entirely sure. My $GOPATH is `/Users/hey/Code/go` but I had placed it in my profile like this `/Users/shanmugharajk/Code/Go`. Case was wrong gave `Go` instead of `go`. I changed this in my bash profile and deleted all the packages outside of vendor folder. After that it works fine. But I try to reproduce the issue by repeating the same it doesn't occur. Finally I couldn't figure the reason for the error and how it got resolved :( – shanmugharaj Mar 11 '18 at 02:38
  • 1
    I believe on mac the GOPATH is case sensitive, I had this problem once, too. – Jonathan R Mar 11 '18 at 10:44

0 Answers0